gpt4 book ai didi

c# - 在 mod_mono (3.12.1) 上运行的 XHR 代理中的 System.Threading.ThreadAbortException

转载 作者:太空宇宙 更新时间:2023-11-04 10:53:54 28 4
gpt4 key购买 nike

我有一个 .NET 2.0 应用程序,我有兴趣将其移植到 Linux 上的 mod_mono 下运行。

应用程序的一部分是 XHR 代理,它提供对提供给前端的各种数据馈送的访问。这个代理脚本确保用户有一个有效的 session ,然后确保用户有权访问他们试图检索的数据。最后,如果请求,代理将使用 Newtonsoft 将 XML 转换为 JSON。

此服务的 URL 如下所示:

/ApiProxy.aspx?url=http%3A%2F%2Fexample%2Fapi%2Fservice

出于某种原因,我无法让这个软件在 mod_mono 下运行。它会产生以下错误:

System.Threading.ThreadAbortException
Thread was being aborted
Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
at (wrapper managed-to-native) System.Threading.Thread:Abort_internal (System.Threading.InternalThread,object)
at System.Threading.Thread.Abort (System.Object stateInfo) [0x00000] in <filename unknown>:0
at System.Web.HttpResponse.End () [0x00000] in <filename unknown>:0
at ASP.apiproxy_aspx.__RenderTree (System.Web.UI.HtmlTextWriter __output, System.Web.UI.Control parameterContainer) [0x00000] in <filename unknown>:0

我真的不知道这个错误是怎么回事。

它似乎没有引用我的任何代码,也没有提供任何关于问题可能出在哪里的提示。我的一个线索是,有一些大块似乎与该问题有关:

using(SqlConnection con = new SqlConnection(myConnectionString))
{
con.Open();

//1) determine if the user is allowed to get the service
//2) retrieve the content the user is requesting
//3) convert the content to json

} catch (Exception ex){
throw new Exception("Unhandled exception", ex);
} finally {
if(con != null)
con.Close();
}
}

当我注释掉 try/catch/finally block 时,行为发生了一点变化,但最终结果仍然是错误。这次是裸露的 400 无效请求错误。

我真的不知道从哪里开始,所以我想我有两个问题:

  1. 导致此错误的原因是什么?
  2. 如何获得更好的诊断信息?

最佳答案

最可能的原因是您在处理请求时超时。在 web.config 中增加超时,错误应该消失。

<location path="apiproxy.aspx">
<system.web>
<httpRuntime executionTimeout="180"/> <!-- set large value here -->
</system.web>
</location>

这里是单声道中HttpResponse.End ()方法的代码https://github.com/mono/mono/blob/master/mcs/class/System.Web/System.Web/HttpResponse.cs#L631-L638

    public void End ()
{
if (context == null)
return;

if (context.TimeoutPossible) {
Thread.CurrentThread.Abort (FlagEnd.Value);
} else {

关于c# - 在 mod_mono (3.12.1) 上运行的 XHR 代理中的 System.Threading.ThreadAbortException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29614517/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com