【发布时间】:2016-09-14 16:17:21
【问题描述】:
我正在将 Web Forms 应用程序从 Forms Authentication 迁移到 OpenID Connect(使用 OWIN 和 IdentityServer3)。 该应用程序在 web.config 中已经有很多“授权”元素(用于不同位置),我希望在迁移到 OWIN 后重用这些元素。
<authorization>
<deny users="?" />
</authorization>
<location path="Path/Page.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
...
问题是,在我切换到 OWIN 而不是被重定向到登录页面后,我得到了 401(未经授权)。
目前将用户重定向到登录页面的唯一方法是在 Page_Load 事件中手动发起挑战:
if (!Request.IsAuthenticated)
{
HttpContext.Current.GetOwinContext().Authentication.Challenge();
}
这就是我的 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",
...
}
...
有没有办法利用网络配置中现有的授权元素,这样我就不必在代码中再次进行这些检查?
【问题讨论】:
标签: c# asp.net asp.net-identity owin identityserver3