• [Log]ASP.NET之HttpModule拦截404异常


    Httpmodule代码:
    public class Error404Module : IHttpModule
        {
            public void Init(HttpApplication context)
            {
                context.Error += new EventHandler(Context_Error);
            }
    
            protected void Context_Error(object sender, EventArgs e)
            {
                HttpContext ctx = HttpContext.Current;
                HttpResponse response = ctx.Response;
                HttpRequest request = ctx.Request;
    
                Exception ex = ctx.Server.GetLastError();
                HttpException hex = ex as HttpException;
                if (hex != null && hex.GetHttpCode() == 404)
                {
                    ctx.Server.ClearError();
                    string url = request.Url.AbsoluteUri.ToLower();
                    if (url.Contains(@"http://hj.woniu.com"))
                    {
                        url = url.Replace(@"http://hj.woniu.com", @"http://sg.hj.woniu.com");
                    }
                    response.Redirect(url, true);
                }
            }
            public void Dispose()
            {
    
            }
        } 
    
    Web.Config配置:
    <httpModules>
          <add name="Error404Module" type="ActHJ.ErrorModules.Error404Module"/>
       </httpModules> 
    
    
    <system.web>
        <compilation debug="false">
          <assemblies>
            <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
            <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
          </assemblies>
          <buildProviders>
            <add extension=".html" type="System.Web.Compilation.PageBuildProvider" />
            <add extension=".htm" type="System.Web.Compilation.PageBuildProvider" />
          </buildProviders>
        </compilation> 
    
    
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules>
          <remove name="ScriptModule"/>
          <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
          <add name="Error404Module" type="ActHJ.ErrorModules.Error404Module"/>
        </modules>
  • 相关阅读:
    codeforces707B:Bakery
    codeforces707A:Brain's Photos
    BZOJ1084 [SCOI2005]最大子矩阵
    BZOJ1264 [AHOI2006]基因匹配Match
    BZOJ2764 [JLOI2011]基因补全
    codevs1257 打砖块
    BZOJ1079 [SCOI2008]着色方案
    BZOJ1026 [SCOI2009]windy数
    菜鸟学自动化测试(一)----selenium IDE
    关于w3school的html5部分output 元素实例代码(点亲自试一试进去)的问题纠正
  • 原文地址:https://www.cnblogs.com/Areas/p/5748025.html
Copyright © 2020-2023  润新知