Asp.net MVC 如果出现错误路由 重定向到首页

Global.asax  添加下面内容

 protected void Application_Error(object sender, EventArgs e)
        {
            Exception ex = Server.GetLastError();

            if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
            {
                Response.Redirect("/home/index");
            }
            else
            {
                // your global error handling here!
            }
        }

posted @ 2023-03-19 15:28  DJ的魔鬼邂逅  阅读(42)  评论(0)    收藏  举报