Asp.net MVC3中进行自定义Error Page

 

在Asp.net MVC3中自定制Error Page 最主要的技术要点是:在web.config 中添加如下节点(指定什么类型的Error跳转到哪个Page);然后在对应的Controller中创建对应的Action指向对应的View。

在web.config中添加的节点:

<customErrors mode="On" defaultRedirect="~/Error" >
  <error statusCode="404" redirect="~/Errors/Error404"/>
</customErrors>

如下请看一个简单的Controller代码:

    public class ErrorsController : Controller
    {
        //
        // GET: /Errors/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Error404()
        {
            return View();
        }

    }

而在纯的Asp.net中也有类似的节点,如下所示:

<configuration>
  <system.web>
    <customErrors defaultRedirect="GenericError.htm"mode="RemoteOnly">
      <error statusCode="500" redirect="InternalError.htm"/>
    </customErrors>
  </system.web>
</configuration>

更多内容请看如下链接:

http://www.codeproject.com/Articles/10593/Error-Handling-in-ASP-NET

原文地址:https://www.cnblogs.com/mingmingruyuedlut/p/2334651.html