use*_*957 5 c# asp.net iis web-services
我们推出了一个经典的 ASP.Net WebService 应用程序,流量很大。尽管我们的数据库运行良好(<10 ms 响应时间),但 WebServer 上花费的大部分时间都在 MapRequestHandler 阶段。
这个问题似乎在 ASP .Net 堆栈中很深,并且没有任何可用的网络信息,我对如何改进它一无所知。
我们对请求/响应使用 XML 有效负载(如果这有助于提供解决方案)。
请发布您的处理程序代码和您的配置文件。
MapRequestHandler- ASP.NET 基础结构使用 MapRequestHandlerevent根据所请求资源的文件扩展名确定当前请求的请求处理程序。MapRequestHandler是event处理程序需要实现的,我怀疑它卡在映射某些自定义文件的某个委托上。
1)没有找到,循环查找自定义文件处理程序,你可能不会2)使用async handler你必须追踪delegate使用它的各种event并设置一个断点
确保它们是Async&Registered例如
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" path="*.config" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="*.asmx" type="System.Web.Services.Protocols.WebServiceHandlerFactory" />
Run Code Online (Sandbox Code Playgroud)
然后在处理程序下验证
<httpHandlers>
<add verb="*" path="*.MyCustomaspx" type="MyCustomHTTPhandler"/>
</httpHandlers>
Run Code Online (Sandbox Code Playgroud)
在您的实现中使用async版本基础处理程序
// dervie from Async HttpTaskAsyncHandler
public class MyCustomHTTPhandler: HttpTaskAsyncHandler {
public override Task ProcessRequestAsync(HttpContext context)
{
//throw new NotImplementedException();
//blah blah.. some code
}
}
Run Code Online (Sandbox Code Playgroud)
最后的手段,不推荐 - 从这里开始,如果您的处理程序/页面不修改会话变量,您可以跳过会话锁定。
Run Code Online (Sandbox Code Playgroud)<% @Page EnableSessionState="ReadOnly" %>
如果您的页面不读取任何会话变量,您可以选择对该页面完全退出此锁定。
Run Code Online (Sandbox Code Playgroud)<% @Page EnableSessionState="False" %>
如果您的页面没有使用会话变量,只需在 web.config 中关闭会话状态即可。
Run Code Online (Sandbox Code Playgroud)<sessionState mode="Off" />
基于此,如果您想仅根据您的特定页面/处理程序自定义会话状态
using System;
using System.Web;
public class CustomSessionStateModule : IHttpModule
{
public void Dispose(){ //.. }
public void Init(HttpApplication context){
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e){
HttpContext currentContext = (sender as HttpApplication).Context;
// here you can filter and turn off/on the session state
if (!currentContext.Request.Url.ToString().Contains("My Custom Handler or Page Value")){
// for e.g. change it to read only
currentContext.SetSessionStateBehavior(
System.Web.SessionState.SessionStateBehavior.ReadOnly);
}
else {
//set it back to default
currentContext.SetSessionStateBehavior(
System.Web.SessionState.SessionStateBehavior.Default);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
485 次 |
| 最近记录: |