开始想到的是在web.config里,但具体怎么写不知道,回来上网查了一下,
说<customErrors mode="On" defaultRedirect="ErrorPage.htm">
<error statusCode="404" redirect="YourNotFoundPage.htm"/>
<error statusCode="500" redirect="YourInternalErrorPage.htm"/>
</customErrors> <customErrors mode="On" defaultRedirect="ErrorPage.htm">
<error statusCode="404" redirect="YourNotFoundPage.htm"/>
<error statusCode="500" redirect="YourInternalErrorPage.htm"/>
</customErrors>
如果这样的话,而statusCode="500",你说的没错,它是一类异常,而不是具体异常。
看到有人说在global里面控制
方法如下:
在Application_Error方法中控制.
protected void Application_Error(Object sender, EventArgs e)
{
Exception Error = Server.GetLastError();
if (Error != null)
{
SqlServer ss = new SqlServer();
string sql = "insert into exception (errorPage,errorLocation,errorReason,errorOuter,errorStackTrace)values";//表中还有出错时间
sql=sql+"('"+ Request.Url.ToString() +"',";
sql=sql+"'"+ Error.InnerException.TargetSite +"',";
sql=sql+"'"+ Error.InnerException.Message +"',";
sql=sql+"'"+ Error.InnerException.ToString() +"',";
sql=sql+"'"+ Error.InnerException.StackTrace +"')";
try
{
ss.execNoReturn(sql);
}
catch(Exception ex)
{
throw ex;
}
finally
{
Server.Transfer(this.Request.ApplicationPath + "//Error.aspx");
}
}
}