110,545
社区成员
发帖
与我相关
我的任务
分享
protected void Application_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
if (ex is HttpException && ((HttpException)ex).GetHttpCode() == 404)
{
string[] path = Request.Url.LocalPath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); ;
Regex regex = new Regex(@"^[A-Za-z0-9]+$");
if (path.Length > 1 || path[0].Length < 3 || !regex.IsMatch(path[0]))
{
//不区分大小写、判断是否包含异常字符
string path2 = "~/Page404.html";
Response.Redirect(path2);
}
else
{
Server.Transfer("Page404.html");
}
}
}