日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

Asp.Net Core 404处理

發(fā)布時間:2023/12/20 asp.net 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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处理的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。