小编MrB*_*rBB的帖子

为什么我未经授权的控制器不返回 401 ASP.Net Core?

我正在使用 Visual Studio 代码,并且正在为 RestAPI 使用 dot net core 框架。当我访问带有“授权”属性的控制器时,它应该返回一个 401 请求,但它不会在邮递员中返回任何内容。只是一片空白。

我认为它应该来自我的启动代码。

我将在启动文件中与您分享我的配置方法。

非常感谢您的帮助。如果您可以在互联网上找到解决方案,只需分享它(我已经在寻找但是...也许我没有输入正确的关键字。)

公共类启动 { 公共启动(IConfiguration 配置){ 配置 = 配置;}

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        ConfigureContext(services);

        services.AddCors();
        services.AddAutoMapper(typeof(Startup));

        // configure strongly typed settings objects
        var appSettingsSection = Configuration.GetSection("AppSettings");
        services.Configure<AppSettings>(appSettingsSection);

        // configure jwt authentication
        var appSettings = appSettingsSection.Get<AppSettings>();
        var key = Encoding.ASCII.GetBytes(appSettings.Secret);
        services.AddAuthentication(x =>
        {
            x.DefaultAuthenticateScheme …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net-core ×1

c# ×1