首页 > 其他分享 >StatusCodeResult.cs

StatusCodeResult.cs

时间:2022-11-20 10:44:26浏览次数:42  
标签:code HTTP int StatusCodeResult cs public StatusCode

https://github.com/dotnet/aspnetcore/blob/39f0e0b8f40b4754418f81aef0de58a9204a1fe5/src/Mvc/Mvc.Core/src/StatusCodeResult.cs#L1

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Microsoft.AspNetCore.Mvc;

/// <summary>
/// Represents an <see cref="ActionResult"/> that when executed will
/// produce an HTTP response with the given response status code.
/// </summary>
public partial class StatusCodeResult : ActionResult, IClientErrorActionResult
{
    /// <summary>
    /// Initializes a new instance of the <see cref="StatusCodeResult"/> class
    /// with the given <paramref name="statusCode"/>.
    /// </summary>
    /// <param name="statusCode">The HTTP status code of the response.</param>
    public StatusCodeResult([ActionResultStatusCode] int statusCode)
    {
        StatusCode = statusCode;
    }

    /// <summary>
    /// Gets the HTTP status code.
    /// </summary>
    public int StatusCode { get; }

    int? IStatusCodeActionResult.StatusCode => StatusCode;

    /// <inheritdoc />
    public override void ExecuteResult(ActionContext context)
    {
        if (context == null)
        {
            throw new ArgumentNullException(nameof(context));
        }

        var httpContext = context.HttpContext;
        var factory = httpContext.RequestServices.GetRequiredService<ILoggerFactory>();
        var logger = factory.CreateLogger<StatusCodeResult>();
        Log.HttpStatusCodeResultExecuting(logger, StatusCode);

        httpContext.Response.StatusCode = StatusCode;
    }

    private static partial class Log
    {
        [LoggerMessage(1, LogLevel.Information, "Executing StatusCodeResult, setting HTTP status code {StatusCode}", EventName = "HttpStatusCodeResultExecuting")]
        public static partial void HttpStatusCodeResultExecuting(ILogger logger, int statusCode);
    }
}

 

标签:code,HTTP,int,StatusCodeResult,cs,public,StatusCode
From: https://www.cnblogs.com/qqhfeng/p/16907984.html

相关文章

  • 第五十二章 开发自定义标签 - Using csr %CSP.AbstractAtom Write Methods
    目录第五十二章开发自定义标签-Usingcsr%CSP.AbstractAtomWriteMethodsWriteTextMethodWriteCSPTextMethodWriteExpressionTextMethodWriteServerMethodWriteC......
  • css文本属性
    文字题颜色设置:文本对齐:text-align (left  center  right )文本装饰:text-decoration  (underline   overline   line-through)文本缩进:text-intend:10p......
  • CSP-J 2022游记
    本文章同步发布于洛谷博客初赛初赛-90天从今年暑假开始学习。教练说我很有天赋,所以暑假直接跟着入门班上。整个暑假就是在持续学基础知识,最后几周开始刷前几年的复......
  • css应用内容总结
     css作为前端三大重要组成之一也是尤为重要得,而且在日常生活中可能关于javascript的相关问题可以组织语言去百度,而对于一些css样式有时候可能却不好组织语言去表述这个问......
  • CSS注册页面练习
    样式      展示      ......
  • CSP-S2022
    勉强混到CQ一等但是差\(5\)分\(7\)级勾(哭)。A.假期计划我们先不考虑\(4\)个点,考虑\(2\)个点的情况。我们发现可以枚举\(a\)点,再找到\(a\)能到达且\(1\)......
  • HTML CSS 注册页面练习
    样式      展示      ......
  • 2022csp普及组真题:解密(decode)
    2022csp普及组真题:解密(decode)题目【题目描述】给定一个正整数 k,有 k 次询问,每次给定三个正整数 ni,ei,di,求两个正整数 pi,qi, 使 ni=pi×qi, ei×......
  • 使用 vlmcsd 部署 KMS 服务器
     一、前言:vlmcsd就是一个仿真KMS管理工具,可以部署在内网或者公网可以运行在Linux、Windows等系统平台上。 由于WindowsVL都是为批量激活而诞生,KMS服务器的作用......
  • 篇(13)-Asp.Net Core入门实战-将功能代码增加异步功能Async和配置简单防范CSRF攻击
    入门实战-将功能代码增加异步功能Async和配置简单防范CSRF攻击关于Asp.NetCore的新特性Async,异步,还是需要掌握的,这个特性,按微软官方的说法是可以提高你服务器的负荷,可以......