C# 使用web.config授权元素时未触发OWIN质询
我正在将Web表单应用程序从表单身份验证迁移到OpenID Connect(使用OWIN和IdentityServer 3)。 该应用程序在web.config中已经有很多“authorization”元素(用于不同的位置),我想在迁移到OWIN后重用这些元素C# 使用web.config授权元素时未触发OWIN质询,c#,asp.net,asp.net-identity,owin,identityserver3,C#,Asp.net,Asp.net Identity,Owin,Identityserver3,我正在将Web表单应用程序从表单身份验证迁移到OpenID Connect(使用OWIN和IdentityServer 3)。 该应用程序在web.config中已经有很多“authorization”元素(用于不同的位置),我想在迁移到OWIN后重用这些元素 <authorization> <deny users="?" /> </authorization> <location path="Path/Page.aspx"> <
<authorization>
<deny users="?" />
</authorization>
<location path="Path/Page.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
...
这就是我的Startup.Auth的样子:
public void ConfigureAuth(IAppBuilder app)
{
//reset the mapping dictionary to ensure the claims are not mapped to .NET standard claims
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "ApplicationCookie",
AuthenticationMode = AuthenticationMode.Active
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = "id",
Authority = IdentityConstants.BaseAddress,
RedirectUri = "uri",
ResponseType = "code id_token token",
SignInAsAuthenticationType = "ApplicationCookie",
Scope = "openid profile email roles offline_access",
...
}
...
public void ConfigureAuth(IAppBuilder应用程序)
{
//重置映射字典以确保声明未映射到.NET标准声明
JwtSecurityTokenHandler.InboundClaimTypeMap=new Dictionary();
app.UseCookieAuthentication(新的CookieAuthenticationOptions
{
AuthenticationType=“ApplicationOkie”,
AuthenticationMode=AuthenticationMode.Active
});
app.UseOpenIdConnectAuthentication(新的OpenIdConnectAuthenticationOptions
{
ClientId=“id”,
Authority=IdentityConstants.BaseAddress,
重定向uri=“uri”,
ResponseType=“代码id\u令牌”,
SignInAsAuthenticationType=“ApplicationOkie”,
Scope=“openid profile电子邮件角色脱机访问”,
...
}
...
有没有办法利用web配置中现有的授权元素,这样我就不必在代码中再次进行这些检查?在app.UseOpenIdConnectAuthentication之后添加以下代码:
app.UseStageMarker(PipelineStage.Authenticate);
这将指示Owin在集成管道中运行。是的,这节省了我的时间
app.UseStageMarker(PipelineStage.Authenticate);