use*_*362 20 .net c# asp.net-mvc
我如何实现以下功能?
我的控制器:
if (something == null)
{
//return the view with 404 http header
return View();
}
//return the view with 200 http header
return View();
Run Code Online (Sandbox Code Playgroud)
fer*_*ero 32
写吧
Response.StatusCode = 404;
Run Code Online (Sandbox Code Playgroud)
在返回视图之前.
dsg*_*fin 15
if (something == null)
{
return new HttpNotFoundResult(); // 404
}
else
{
return new HttpStatusCodeResult(HttpStatusCode.OK); // 200
}
Run Code Online (Sandbox Code Playgroud)
if (something == null)
{
Response.StatusCode = (int)HttpStatusCode.NotFound;
return View();
}
//return the view with 200 http header
return View();
Run Code Online (Sandbox Code Playgroud)
您应该将TrySkipIisCustomErrors属性设置Response为true.
public ActionResult NotFound()
{
Response.StatusCode = 404;
Response.TrySkipIisCustomErrors = true;
return View();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23023 次 |
| 最近记录: |