Asp.Net Core 404处理

在使用Asp.Net Core Mvc时 404处理整理以下html

1、自带404状态处理post

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状态,或者返回404的一句话提示。url

 

2、自定义404页面显示spa

在网站中,为了加强提早,一般使用自定义404页面code

1.自定义404视图,在控制器中返回htm

    /// <summary>
    /// 定义404视图
    /// </summary>
    public class NotFoundViewResult : ViewResult
    {
        public NotFoundViewResult(string viewName)
        {
            ViewName = viewName;
            StatusCode = (int)HttpStatusCode.NotFound;
        }
    }

2.在控制器中返回使用blog

        public IActionResult Index()
        {
            //返回404页面
            return new NotFoundViewResult("~/views/Error/code_404.cshtml");

            return View();
        }

3.呈现结果:get

 

3、更多错误处理string

更多:

Asp.Net Core异常处理整理

.Net Core邮件发送之MailKit

Asp.Net Core中Json序列化处理整理

相关文章
相关标签/搜索