zoukankan      html  css  js  c++  java
  • global中拦截404错误的实现方法

    1.

        void Application_Error(object sender, EventArgs e)
        {
        if(Context != null)
        {
        HttpContext ctx = HttpContext.Current;
        Exception ex = ctx.Server.GetLastError();
        HttpException ev = ex as HttpException;
        if(ev!= null)
        {
        if(ev.GetHttpCode() == 404)
        {
        ctx.ClearError();
        Response.Redirect("~/nofound.aspx", false);
        Response.End();
        }
        else
        {
        Server.Transfer("~/Error.aspx", false);
        }
        }
        }
        }

    2.

            //全站 Error 处理
            protected void Application_Error()
            {
                //获取关于当前请求的 HTTP 特定信息。
                if (Context != null)
                {
                    Exception ex = HttpContext.Current.Server.GetLastError() as Exception;
                    //HttpException ex = Context.Server.GetLastError() as HttpException;
                    if (ex != null)
                    {
                        //404
                        if (ex is HttpException)
                        {
                            HttpException hEx = ex as HttpException;
                            if (hEx.GetHttpCode() == 404)
                            {
                                Context.ClearError();
                                Context.Response.Redirect("~/RouteOne/NotFind/?from=" + Context.Request.UrlReferrer);
                                Context.Response.End();
                            }
                        }
                        else
                        {
                            //服务器错误
                            //Context.Server.Transfer("~/RouteOne/Error/?msg=" + ex.Message);
                            Context.Response.Redirect("~/RouteOne/Error/?msg=" + Context.Request.UrlReferrer);
                            Context.Response.End();
                        }
                    }
                }
            }
  • 相关阅读:
    正交矩阵(部分转载)
    向量的点乘和叉乘
    随机森林
    PCA和LDA
    SIFT和SURF特征(草稿)
    12-赵志勇机器学习-Label_Propagation
    11-赵志勇机器学习-DBSCAN聚类
    09-赵志勇机器学习-k-means
    10-赵志勇机器学习-meanshift
    09-numpy-笔记-repeat
  • 原文地址:https://www.cnblogs.com/tianma3798/p/4235681.html
Copyright © 2011-2022 走看看