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

来源:互联网 发布:上海大学校园有线网络 编辑:程序博客网 时间:2024/05/18 00:01

备忘。

 

下面这个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);}


 

0 0
原创粉丝点击