Asp.Net Core 404处理
生活随笔
收集整理的這篇文章主要介紹了
Asp.Net Core 404处理
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在使用Asp.Net Core Mvc時 404處理整理如下
一、自帶404狀態(tài)處理
1.控制器視圖子彈404視圖?NotFoundResult,NotFoundObjectResult
//// 摘要:// Creates an Microsoft.AspNetCore.Mvc.NotFoundObjectResult that produces a Microsoft.AspNetCore.Http.StatusCodes.Status404NotFound// response.//// 返回結果:// The created Microsoft.AspNetCore.Mvc.NotFoundObjectResult for the response. [NonAction]public virtual NotFoundObjectResult NotFound(object value);//// 摘要:// Creates an Microsoft.AspNetCore.Mvc.NotFoundResult that produces a Microsoft.AspNetCore.Http.StatusCodes.Status404NotFound// response.//// 返回結果:// The created Microsoft.AspNetCore.Mvc.NotFoundResult for the response. [NonAction]public virtual NotFoundResult NotFound();2.當前操作返回404狀態(tài),或者返回404的一句話提示。
?
二、自定義404頁面顯示
在網(wǎng)站中,為了增強提前,通常使用自定義404頁面
1.自定義404視圖,在控制器中返回
/// <summary>/// 定義404視圖/// </summary>public class NotFoundViewResult : ViewResult{public NotFoundViewResult(string viewName){ViewName = viewName;StatusCode = (int)HttpStatusCode.NotFound;}}2.在控制器中返回使用
public IActionResult Index(){//返回404頁面return new NotFoundViewResult("~/views/Error/code_404.cshtml");return View();}3.呈現(xiàn)結果:
?
三、更多錯誤處理
更多:
Asp.Net Core異常處理整理
.Net Core郵件發(fā)送之MailKit
Asp.Net Core中Json序列化處理整理
轉載于:https://www.cnblogs.com/tianma3798/p/10122910.html
總結
以上是生活随笔為你收集整理的Asp.Net Core 404处理的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 理解Bias(偏差),Error(误差)
- 下一篇: 洛咕 P4474 王者之剑