小编spo*_*ahn的帖子

如何使用.Net Core授权AD用户

我正在尝试使用Authorize注释停止路由上的请求,但我无法使用Active Directory.有人有这个工作吗?

[HttpGet]
[Authorize(Roles = "DOMAIN\\Group A")]
[Route("/")] // GET: /
public IActionResult Index()
{
    return View();
}
Run Code Online (Sandbox Code Playgroud)

注意:我也试过了 Authorize(Roles = @"DOMAIN\\Group A")

为了给出一些背景知识,我正在运行Windows,Visual Studio Pro 2015(更新3)

从我的project.json文件中得到一点:

"dependencies": {
    "Microsoft.AspNetCore.Authorization": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Swashbuckle.SwaggerGen": "6.0.0-beta901",
    "Swashbuckle.SwaggerUi": "6.0.0-beta901"
  }
Run Code Online (Sandbox Code Playgroud)

authorization asp.net-core

6
推荐指数
1
解决办法
6598
查看次数

如何在 ASP.Net Core 中组合/组合授权处理程序?

如何重用来组成两个处理程序的AuthorizationHandlers复合需求?

  • RequirementA与一个处理程序IsAllowedAccessToA : AuthorizationHandler<RequirementA>
  • RequirementB与一个处理程序IsAllowedAccessToB : AuthorizationHandler<RequirementB>
  • RequirementA_OR_B如果在哪里相遇IsAllowedAccessToAIsAllowedAccessToB成功

我拥有只能访问的资源,RequirementA并且对于RequirementB. 我也有 A 或 B 可以使用的资源。

我不知道如何在没有重复IsAllowedAccessToAIsAllowedAccessToB处理程序的情况下做到这一点

本文有所帮助,但并非完全相同的用例。

authorization asp.net-core

6
推荐指数
1
解决办法
2130
查看次数

6
推荐指数
1
解决办法
1138
查看次数

asp net core 2 和 Azure AD B2C,添加基于组的授权

我正在创建一个使用 azure AD B2C 进行身份验证的 asp net core 2 web api。我想使用 AD B2C 组将某些控制器的使用限制为管理员成员。

我已经明白,目前实现这一目标的唯一方法是访问图形 API 并将一些角色声明添加到用户的声明中。

但是我在启动时查询图形 api 时遇到了麻烦。

我的ConfigureService方法是这样的:

services.AddAuthentication(sharedOptions =>
        {
            sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
        })
       .AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options))
            .AddJwtBearer(options => {
                options.Authority = string.Format("https://login.microsoftonline.com/tfp/{0}/{1}/v2.0/", "b2ctenant.onmicrosoft.com", "B2C_1_DefaultSignUpIn");
                options.Audience = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";
                options.Events = new JwtBearerEvents
                {
                    OnTokenValidated = OnAuthorizationCodeReceived,
                };
            })
       .AddCookie(options =>
       {
           options.LoginPath = "/Account/SignIn";
           options.LogoutPath = "/Account/SignOut";
           options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
           options.Events = new CookieAuthenticationEvents
           {
               OnRedirectToLogin = OnRedirectToLogin
           };
       }); …
Run Code Online (Sandbox Code Playgroud)

azure-ad-graph-api azure-ad-b2c asp.net-core-webapi asp.net-core-2.0

6
推荐指数
0
解决办法
1257
查看次数

Azure B2C身份验证中的"范围"有什么用?

我不明白如何使用Azure B2C中的"范围".它们与API相关联,但与用户无关.我确定我遗漏了一些东西,但我认为与API相关的东西没有实际用途.我已经根据用户在数据库中的角色使用并实现了基于声明的身份验证.

例如:API的普通用户不应具有删除对象的权限,但管理员具有权限.有人有一个实际的例子说明如何使用这些B2C"范围"来限制用户对API的访问吗?

azure-ad-b2c

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

ASP.NET Core 2.1自定义RoleProvider与Windows身份验证

我正在将应用程序从ASP.Net MVC 5框架迁移到新的.Net Core 2.1.

我在MVC 5项目中使用了Windows身份验证和自定义RoleProvider,如下面的链接所示.

ASP.NET MVC如何创建自定义角色提供程序

如何在Core 2.1中完成相同的操作,因为它似乎不包含RoleProvider功能?

我遇到的每个示例都使用IdentityUser和IdentityRole的个人帐户.

用户和角色的自定义表格:

public class User
{
    public User() { UserRoles = new HashSet<UserRole>(); }

    [Key]
    public string Id { get; set; }

    [StringLength(50)]
    [Required]
    public string Logon { get; set; } //The users Active Directory Username

    public bool Active { get; set; }

    public ICollection<UserRole> UserRoles { get; set; }

}


public class Role
{
    public Role() { UserRoles = new HashSet<UserRole>(); }

    [Key]
    public string Id { get; …
Run Code Online (Sandbox Code Playgroud)

c# roles asp.net-core-mvc asp.net-core asp.net-core-2.0

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

在 Azure Functions 的 SignalR 服务中向一组用户发送消息

查看SignalR 绑定的文档以向指定用户发送消息,您UserId在消息中包含该属性 -

[FunctionName("SendMessage")]
public static Task SendMessage(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post")]object message, 
    [SignalR(HubName = "chat")]IAsyncCollector<SignalRMessage> signalRMessages)
{
    return signalRMessages.AddAsync(
        new SignalRMessage 
        {
            // the message will only be sent to these user IDs
            UserId = "userId1",
            Target = "newMessage", 
            Arguments = new [] { message } 
        });
}
Run Code Online (Sandbox Code Playgroud)

此示例直接取自文档,但注释暗示您向多个用户 ID发送消息,即使该属性是字符串而不是数组。

您将如何指定多个用户?(例如,如果他们一起在私人聊天频道中)或者评论的措辞是否存在错误,您需要为每个用户发送一条消息?

对于其他版本的 SignalR,我会将它们放在一个组中,但函数不存在此绑定。

azure azure-functions signalr-service

6
推荐指数
1
解决办法
2125
查看次数

已存在同名的查询类型

无法将实体类型“MyType”添加到模型中,因为已存在同名的查询类型。

public class MyContext : DbContext
{
    public DbQuery<MyType> MyTypes { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        //Exception is thrown here

        //needed b/c table is not named MyTypes
        modelBuilder.Entity<MyType>()
            .ToTable("MyType");
    }
}
Run Code Online (Sandbox Code Playgroud)

entity-framework-core

6
推荐指数
1
解决办法
2096
查看次数

使用 dotnet add 包忽略无法访问的源

当我尝试通过 cli 添加 NuGet 包时,dotnet出现错误,指出它无法访问我的自定义 NuGet 源之一。有没有办法说“我不在乎,从你可以恢复的地方恢复”?

\n\n

McMaster.Extensions.CommandLineUtils显然它存在于 NuGet.org 中,并且找到它,但随后停止,因为它无法访问自定义源 \xe2\x80\x8d\xe2\x99\x82\xef\xb8\x8f。

\n\n
\n

PS c:\\Temp\\blah-project> dotnet add package McMaster.Extensions.CommandLineUtils
\n info : 将包 \'McMaster.Extensions.CommandLineUtils\' 的 PackageReference 添加到项目 \'c:\\Temp\\blah-项目\\blah-project.csproj\'。
\n 信息:恢复 c:\\Temp\\blah-project\\blah-project.csproj 的包
\n 信息:GET https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index .json
\n 信息:确定https://api.nuget.org/v3-flatcontainer/mcmaster.extensions.commandlineutils/index.json 147ms
\n 错误:无法加载源https://myinstace.pkgs的服务索引.visualstudio.com/_packaging/Blah/nuget/v3/index.json
\n 错误:响应状态代码不表示成功:401(未经授权)。

\n
\n

c# command-line-interface nuget .net-core

6
推荐指数
1
解决办法
2947
查看次数

如何在asp .net core 3.1中设置请求超时

  • 从 Visual Studio 中选择创建新项目。选择 ASP.NET Core 3.1
  • 在 IIS 中发布和托管
  • 增加上传文件大小此代码:
public void ConfigureServices(IServiceCollection services)
{
    services.Configure<IISServerOptions>(options =>
    {
        options.MaxRequestBodySize = 314572800;
    });

    services.AddControllersWithViews();
}
Run Code Online (Sandbox Code Playgroud)

和网络配置:

<security>
    <requestFiltering>
      <!-- This will handle requests up to 300MB -->
      <requestLimits maxAllowedContentLength="314572800" />
    </requestFiltering>
</security>
Run Code Online (Sandbox Code Playgroud)

以上正确适用,但默认超时为 2 分钟

如何增加 IIS 中托管的 ASP.NET Core 3.1 应用程序的超时时间?

注意:我的 web.config

<aspNetCore processPath="dotnet" arguments=".\AspCoreTestFileUpload.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
Run Code Online (Sandbox Code Playgroud)

对于 requestTimeout :不适用于进程内托管。对于进程内托管,模块等待应用程序处理请求。

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1#attributes-of-the-aspnetcore-element

我必须使用进程内托管模型

iis publish request-timed-out asp.net-core

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