【问题标题】:ASP .Net MapRequestHandler slowASP .Net MapRequestHandler 慢
【发布时间】:2017-07-08 16:02:36
【问题描述】:

我们推出了一个经典的 ASP.Net WebService 应用程序,流量很大。虽然我们的数据库运行良好(

这个问题似乎在 ASP .Net 堆栈中很深,并且没有任何可用的信息在网上,我不知道如何去改进它。

我们使用 XML 有效负载进行请求/响应(如果这有助于提供解决方案)。

【问题讨论】:

  • 忘了说,我试图删除除 .asmx 和其他少数几个以外的大部分处理程序映射(在 IIS 中),但没有帮助。

标签: c# asp.net web-services iis


【解决方案1】:

请发布您的处理程序代码和您的配置文件。

MapRequestHandler - MapRequestHandler event 被 ASP.NET 基础结构用于确定 基于所请求资源的文件扩展名的当前请求的请求处理程序。 MapRequestHandler 是处理程序需要实现的event,我怀疑它卡在某个映射某个自定义文件的委托上。

我怀疑它的 1) 找不到,循环查找该自定义文件处理程序,您可能不会 2) 使用 async handler

你必须追查使用这个event的各种delegate并设置一个断点

确保它们是 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" />

然后在handlers下验证

<httpHandlers>

   <add verb="*" path="*.MyCustomaspx" type="MyCustomHTTPhandler"/>

</httpHandlers>

在您的实现中使用async 版本基础处理程序

 // dervie from Async HttpTaskAsyncHandler 
 public class MyCustomHTTPhandler: HttpTaskAsyncHandler {    
       public override Task ProcessRequestAsync(HttpContext context)    
       {    
           //throw new NotImplementedException();    
           //blah blah.. some code
       }    
   }

不得已,不推荐 - 来自SO here,如果您的处理程序/页面不修改会话变量,您可以跳过会话锁定。

<% @Page EnableSessionState="ReadOnly" %>

如果您的页面没有读取任何会话变量,您可以为该页面选择完全退出此锁定。

<% @Page EnableSessionState="False" %>

如果您的页面都没有使用会话变量,只需在 web.config 中关闭会话状态即可。

<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);
        }    
     }
 }

【讨论】:

    猜你喜欢
    • 2011-03-25
    • 2021-06-30
    • 2022-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多