我正在尝试使用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) 如何重用来组成两个处理程序的AuthorizationHandlers复合需求?
RequirementA与一个处理程序IsAllowedAccessToA : AuthorizationHandler<RequirementA>RequirementB与一个处理程序IsAllowedAccessToB : AuthorizationHandler<RequirementB>RequirementA_OR_B如果在哪里相遇IsAllowedAccessToA或IsAllowedAccessToB成功我拥有只能访问的资源,RequirementA并且对于RequirementB. 我也有 A 或 B 可以使用的资源。
我不知道如何在没有重复IsAllowedAccessToA和IsAllowedAccessToB处理程序的情况下做到这一点
本文有所帮助,但并非完全相同的用例。
我正在创建一个使用 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
我不明白如何使用Azure B2C中的"范围".它们与API相关联,但与用户无关.我确定我遗漏了一些东西,但我认为与API相关的东西没有实际用途.我已经根据用户在数据库中的角色使用并实现了基于声明的身份验证.
例如:API的普通用户不应具有删除对象的权限,但管理员应具有权限.有人有一个实际的例子说明如何使用这些B2C"范围"来限制用户对API的访问吗?
我正在将应用程序从ASP.Net MVC 5框架迁移到新的.Net Core 2.1.
我在MVC 5项目中使用了Windows身份验证和自定义RoleProvider,如下面的链接所示.
如何在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) 查看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,我会将它们放在一个组中,但函数不存在此绑定。
无法将实体类型“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) 当我尝试通过 cli 添加 NuGet 包时,dotnet出现错误,指出它无法访问我的自定义 NuGet 源之一。有没有办法说“我不在乎,从你可以恢复的地方恢复”?
McMaster.Extensions.CommandLineUtils显然它存在于 NuGet.org 中,并且找到它,但随后停止,因为它无法访问自定义源 \xe2\x80\x8d\xe2\x99\x82\xef\xb8\x8f。
\n\n\n\nPS c:\\Temp\\blah-project> dotnet add package McMaster.Extensions.CommandLineUtils
\n
\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(未经授权)。
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 :不适用于进程内托管。对于进程内托管,模块等待应用程序处理请求。
我必须使用进程内托管模型
asp.net-core ×4
azure-ad-b2c ×3
c# ×2
.net-core ×1
azure ×1
iis ×1
nuget ×1
publish ×1
roles ×1