您的位置:首页 > 理论基础 > 计算机网络

如何正确的为web.config编写http error code的自定义页面

2015-04-01 17:28 459 查看
备忘。

 

下面这个subStatusCode,呃,有时很有用的。

<system.webServer>
<httpErrors errorMode="Custom">
<remove statusCode="404" subStatusCode="0" />
<error statusCode="404" subStatusCode="0" path="/home/http/404" responseMode="ExecuteURL" />
<remove statusCode="400"/>
<error statusCode="400" path="/home/http/400" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>

 

以下这一段常常不起作用,所以也就不要用这种方式了。

<system.web>
<customErrors mode="On" defaultRedirect="/home/http/0">
<error statusCode="404" redirect="/home/http/404" />
<error statusCode="500" redirect="/home/http/500" />
</customErrors>
</system.web>


 关于C#就简单了

public ActionResult Http(string id)
{
string viewName = "~/Views/Shared/http" + id + ".cshtml";
if (!System.IO.File.Exists(Server.MapPath(viewName)))
{
viewName = "~/Views/Shared/Error.cshtml";
}
return View(viewName);
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐