ASP.NET08

配置错误页

1
2
3
4
5
6
7
8
9
10
11
<customErrors mode="On" defaultRedirect="~/test2/404.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
---------------------------在Application_Error中发生错误时转向另外一个页面------------------------
protected void Application_Error(object sender, EventArgs e)
{
string errorMsg = Context.Error.Message + Environment.NewLine + Context.Error.StackTrace + "【" + DateTime.Now.ToString() + "】" + Environment.NewLine + "====================================================" + Environment.NewLine;
File.AppendAllText(Server.MapPath("~/log.txt"), errorMsg);
Response.Redirect("~/test2/404.htm");
}

mvc中只能将静态页面放在根目录或者创建一个Error控制器