zhs493972592 发表于 2013-11-29 02:14:27

远古VOD点播能装在win7或2008上吗

我试了win7 老是错误 无法访问网络位置

zhs493972592 发表于 2013-11-29 02:26:11

MVC TIP4:为捕获路由及通用异常处理
Tags: 捕获路由 异常处理 mvc
1:首先,准备控制器




123456789101112131415161718192021222324252627 public class ErrorController : Controller
{
      public ActionResult Index(string error)
      {
            ViewData["Title"] = "WebSite 网站内部错误";
            ViewData["Description"] = error;
            return View("Index");   //全部路由到Error下的Index视图
      }
      public ActionResult HttpError404(string error)
      {
            ViewData["Title"] = "HTTP 404- 无法找到文件";
            ViewData["Description"] = error;
            return View("Index");
      }
      public ActionResult HttpError500(string error)
      {
            ViewData["Title"] = "HTTP 500 - 内部服务器错误";
            ViewData["Description"] = error;
            return View("Index");
      }
      public ActionResult General(string error)
      {
            ViewData["Title"] = "HTTP 发生错误";
            ViewData["Description"] = error;
            return View("Index");
      }
}




2:Error下的Index视图



代码:






3:在Global.aspx中进行处理

添加如下方法:

1234567891011121314151617181920212223242526272829303132333435363738 protected void Application_Error(object sender, EventArgs e)
      {
            Response.Clear();
            Exception exception = Server.GetLastError();
            HttpException httpException = exception as HttpException;
            RouteData routeData = new RouteData();
            routeData.Values.Add("controller", "Error");
            if (exception == null)
            {
                routeData.Values.Add("action", "Index");
            }
            else if (httpException == null)
            {
                routeData.Values.Add("action", "Index");
            }
            else
            {
                switch (httpException.GetHttpCode())
                {
                  case 404:
                        routeData.Values.Add("action", "HttpError404");
                        break;
                  case 500:
                        routeData.Values.Add("action", "HttpError500");
                        break;
                  default:
                        routeData.Values.Add("action", "General");
                        break;
                }
            }
            // Pass exception details to the target error View.
            routeData.Values.Add("error", exception.Message);
            // Clear the error on server.
            Server.ClearError();
            // Call target Controller and pass the routeData.
            IController errorController = new ErrorController();
            errorController.Execute(new RequestContext(new HttpContextWrapper(Context), routeData));

sunshinezero 发表于 2013-11-29 13:06:23

学习当中学习当中学习当中学习当中学习当中学习当中
页: [1]
查看完整版本: 远古VOD点播能装在win7或2008上吗