且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

处理ASP.NET MVC时出错

更新时间:2022-05-16 03:17:14

解决我的问题只需添加

Response.ContentType = text / html;

其他方法:

我找到了其他自定义错误的方法。

I find some other way to make custom errors.

web.config

<system.webServer>
  <httpErrors errorMode="Custom" existingResponse="Replace">
    <remove statusCode="404" />
    <error statusCode="404" responseMode="ExecuteURL" path="/Error/Http404" />
  </httpErrors>
</system.webServer>

控制器

public class ErrorController : Controller
{
    public ActionResult PageNotFound()
    {
        Response.StatusCode = 404;
        return View();
    }
}

这对我有用。