为什么一个web请求要为我的defaultdocument页面创建第二个单独的线程调用?

时间:2022-04-04 21:01:30

I'm seeing some very strange behaviour when debugging my web application in VS2010 locally. The same user journey/sequence of pages happens in Production.

在本地VS2010中调试web应用程序时,我看到了一些非常奇怪的行为。相同的用户旅程/页面顺序发生在生产中。

Debugging, I'm seeing this:

调试,我看到这个:

1. request for MyPage.aspx - handled by thread_1
2. (there is something on that page that IIS/ASP.Net doesn't like it seems) I'm slowly removing sections to pin-point exactly but there's
no JS, or anything fancy there just html content, user controls etc.
3. Either way a separate thread_2 to begin processing the Page_Load of my defaultdocument i.e. home.aspx is executed. There is logic in
home.aspx.cs to clear some data.
4. So when thread_1 continues processing, checks against the data above fail, resulting with the user being redirected to an error page.

Can anyone shed any light on why the second thread is created and why it starts to process my default document?

谁能解释为什么第二个线程被创建,以及为什么它开始处理我的默认文档?

Please note:

请注意:

  • I've checked the global methods for errors e.g. session_end, app_error etc but nothing.
  • 我已经检查了全局方法的错误,例如session_end、app_error等等,但是什么都没有。
  • I do intermittently see a 401 error with Failed Request Tracing Logging enabled but I don't understand how that would start the processing of my default home page?
  • 我确实间歇性地看到了一个401错误,它启用了失败的请求跟踪日志记录,但我不明白这将如何开始处理我的默认主页?
  • just to sanity check, I placed a new doc test.aspx at the beginning of my defaultdocument list in the web.config and it did get called.
  • 为了检查是否正常,我放置了一个新的doc测试。在我的默认文档列表的开头的aspx。config和它确实被调用了。

It seems as though, something within IIS/ASP.Net is configured to begin processing the default page on an error but this is new behaviour to me?

好像是IIS/ASP中的一些东西。Net配置为开始处理错误上的默认页面,但这对我来说是新的行为?

I've tried researching this but the only thing that seems that it could be related is thread-agility but I'm not too sure..?

我已经尝试过研究这个问题,但唯一可能与之相关的是线程敏捷性,但我不太确定。

2 个解决方案

#1


1  

It seems like there are two HTTP requests running concurrently. As each request (generally) executes on its on thread this condition would make sense.

似乎有两个HTTP请求同时运行。当每个请求(通常)在线程上执行时,这个条件是有意义的。

HTTP requests by default do not share state. They operate on different data. For that reason this is not a thread-safety issue.

默认情况下,HTTP请求不共享状态。它们对不同的数据进行操作。因此,这不是一个线程安全问题。

An exception to this rule is if you explicitly share state e.g. using static variables. You shouldn't do this for various reasons.

这个规则的一个例外是如果您显式地共享状态,例如使用静态变量。你不应该因为各种原因这样做。

To debug the problem launch Fiddler and examine the HTTP request being executed. Also example HttpContext.Current.Request.RawUrl on each of the two concurrent threads.

要调试问题,请启动Fiddler并检查正在执行的HTTP请求。还HttpContext.Current.Request示例。两个并发线程中的每个线程上的RawUrl。

#2


0  

After removing a lot of content within the faulty MyPage.aspx, I came across the guilty line of code: btnShowPost.ImageUrl = SitePath + "post.png"; (it was never accessed behind an if statement) and therefore the image <asp:Image ID="btnShowPost" runat="server" /> never set the necessary ImageUrl.

在删除了错误页面中的大量内容之后。aspx,我遇到了错误的代码行:btnShowPost。ImageUrl = SitePath +“post.png”;(从不在if语句后面访问它),因此图像 从不设置必要的ImageUrl。

Without it, apparently this is standard browser behavior: any img, script, css, etc, with a src= missing, will use the default path as the url. iis will usually redirect to default.aspx (or whatever is the default).

没有它,显然这是标准的浏览器行为:任何img、脚本、css等等,如果src=缺失,将使用默认路径作为url。iis通常会重定向到默认值。aspx(或任何默认值)。

See full explanation on this link

请参阅此链接的完整解释

#1


1  

It seems like there are two HTTP requests running concurrently. As each request (generally) executes on its on thread this condition would make sense.

似乎有两个HTTP请求同时运行。当每个请求(通常)在线程上执行时,这个条件是有意义的。

HTTP requests by default do not share state. They operate on different data. For that reason this is not a thread-safety issue.

默认情况下,HTTP请求不共享状态。它们对不同的数据进行操作。因此,这不是一个线程安全问题。

An exception to this rule is if you explicitly share state e.g. using static variables. You shouldn't do this for various reasons.

这个规则的一个例外是如果您显式地共享状态,例如使用静态变量。你不应该因为各种原因这样做。

To debug the problem launch Fiddler and examine the HTTP request being executed. Also example HttpContext.Current.Request.RawUrl on each of the two concurrent threads.

要调试问题,请启动Fiddler并检查正在执行的HTTP请求。还HttpContext.Current.Request示例。两个并发线程中的每个线程上的RawUrl。

#2


0  

After removing a lot of content within the faulty MyPage.aspx, I came across the guilty line of code: btnShowPost.ImageUrl = SitePath + "post.png"; (it was never accessed behind an if statement) and therefore the image <asp:Image ID="btnShowPost" runat="server" /> never set the necessary ImageUrl.

在删除了错误页面中的大量内容之后。aspx,我遇到了错误的代码行:btnShowPost。ImageUrl = SitePath +“post.png”;(从不在if语句后面访问它),因此图像 从不设置必要的ImageUrl。

Without it, apparently this is standard browser behavior: any img, script, css, etc, with a src= missing, will use the default path as the url. iis will usually redirect to default.aspx (or whatever is the default).

没有它,显然这是标准的浏览器行为:任何img、脚本、css等等,如果src=缺失,将使用默认路径作为url。iis通常会重定向到默认值。aspx(或任何默认值)。

See full explanation on this link

请参阅此链接的完整解释