小编Ale*_*exu的帖子

如何在 VS.net 解决方案中将 .Net 标准项目迁移到 .Net 5?

我有一个包含 .Net CORE 和 .Net 标准项目的 VS 解决方案。我刚刚通过如下切换目标框架属性将所有 .Net CORE 项目更改为使用 .Net 5 在此处输入图片说明

但是我不能对 .Net 标准项目做同样的事情,因为框架属性下拉菜单没有 .Net 5 的选项。

在此处输入图片说明

我确实尝试了“安装其他框架”选项并安装了 .Net 5 SDK(不知道为什么我需要这样做,因为我的系统上已经有了 .Net 5)但它没有帮助 - 下拉菜单仍然没有之后有.Net 5。

我在这里缺少什么?

.net-standard .net-5

8
推荐指数
2
解决办法
2500
查看次数

为什么RequiredScope属性没有任何作用?

根据此 Microsoft 文档,您应该能够将 [RequiredScope("SomeScopeName")] 等属性应用到控制器级别或操作级别以保护 API。但是当我在 API 中尝试它时,它似乎根本没有任何效果 - 无论我使用什么范围名称(我确保令牌中没有该名称的范围),我总是正确的进入我应该失败的 API 操作。但与此同时,我的策略属性,例如 [Authorize(Policy = "PolicyName")],工作得很好。我缺少什么?

[ApiController]
[RequiredScope("AnyRandomName")]
public class MyApiController : ControllerBase
{
Run Code Online (Sandbox Code Playgroud)

更新

这是我的 Startup.cs

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }
    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        IdentityModelEventSource.ShowPII = true; 
        services.AddControllers();

        services.AddSwaggerGen(opt =>
        {
            opt.CustomSchemaIds(type => type.ToString() + type.GetHashCode()); 
        });

        services.Configure<HostOptions>(Configuration.GetSection(HostOptions.HOST));

        JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear(); 
        JwtSecurityTokenHandler.DefaultOutboundClaimTypeMap.Clear();
        services.AddAuthentication("Bearer").AddJwtBearer(options =>
        {
            options.Authority = Configuration[HostOptions.IDENTITYGATEWAY];
            options.SaveToken = true;
            options.TokenValidationParameters = new TokenValidationParameters …
Run Code Online (Sandbox Code Playgroud)

api-authorization asp.net-core-webapi

6
推荐指数
2
解决办法
7706
查看次数

在.Net 5下使用HTTPS调用gRPC服务时出现证书错误:UntrustedRoot

我正在尝试通过 HTTPS 连接我的 gRPC 客户端和服务,它们都在我的本地 Windows 10 计算机上的 .Net 5 下运行。现在我收到此证书错误,但不知道如何修复它:

    Status(StatusCode=\"Internal\", Detail=\"Error starting gRPC call. 
    HttpRequestException: The SSL connection could not be established, see inner exception. 
    
    AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot\", DebugException=\"System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.\r\n 
---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid because of errors in the certificate chain: UntrustedRoot\r\n   at System.Net.Security.SslStream.SendAuthResetSignal(ProtocolToken message, ExceptionDispatchInfo exception)\r\n   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean …
Run Code Online (Sandbox Code Playgroud)

https grpc .net-5

5
推荐指数
1
解决办法
6163
查看次数

为什么 Serilog 不写入 ASP.Net core 应用程序中的日志文件?

我正在尝试在 ASP.Net Core 应用程序中使用 Serilog,但无法让它工作。一旦我在 Program.cs 中添加 .UseSerilog(),通常进入控制台屏幕的消息就会消失,并且不会创建任何日志文件。以下是我启用 Serilog 的方法:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
    .UseSerilog()
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
    })
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序设置:

  "Logging": {
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Grpc": "Information",
      "Microsoft": "Information",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*"
Run Code Online (Sandbox Code Playgroud)

据我所知,默认情况下,日志文件似乎会被写入 VS.net 项目下的“logs”文件夹中(至少从我查看的示例来看是这样)。我想念什么?

serilog asp.net-core

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

identityserver4 由于证书链错误,远程证书无效:untrustedroot

我在 HTTPS 下使用 IIS 服务器托管我的 IdentityServer、Web API 和 MVC 客户端应用程序。当我运行我的 MVC 客户端时,我收到以下错误(注意 - 6009 是我的 MVC 客户端的端口,6005 是我的 IdentityServer 的端口):

在此处输入图片说明

当我在 IIS 中配置它们时,我正在为所有项目使用 IIS Express 开发证书:

在此处输入图片说明

我将证书从个人商店复制到受信任的根目录,如下所示:

在此处输入图片说明

这是证书的详细信息:

在此处输入图片说明

我在这里还缺少什么?

ssl-certificate asp.net-core-mvc identityserver4

1
推荐指数
2
解决办法
3434
查看次数