Jul*_*amp 2 asp.net authentication asp.net-mvc ws-federation owin
我在使用WsFederation AuthenticationMVC Web应用程序时遇到登录循环问题.我用Visual Studio来创建Web应用程序的脚手架和来设置WsFederation的Startup.cs.这会生成以下代码块:
public class Startup
{
private static string realm = ConfigurationManager.AppSettings["ida:Wtrealm"];
private static string adfsMetadata = ConfigurationManager.AppSettings["ida:ADFSMetadata"];
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseWsFederationAuthentication(new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
}
}
Run Code Online (Sandbox Code Playgroud)
Web应用程序托管在Azure中,ADFS位于内部.
在某些客户端上,当进行登录尝试时,登录页面进入循环,请求新令牌在ADFS服务器上导致以下异常:
异常详细信息:Microsoft.IdentityServer.Web.InvalidRequestException:MSIS7042:同一客户端浏览器会话在最后"7"秒内发出了"6"个请求.请联系您的管理员了解详情
我已经阅读了很多关于StackOverflow的文章,并查看了编写IdentityServer的人提供的各种示例,我尝试了各种配置选项,我无法将问题隔离到特定区域.
从我读到的内容来看,OWIN中间件丢失了对象的上下文,因此令牌"丢失".
我试图实现其他一些在StackOverflow上提供的示例代码但是,我似乎找不到解决方案来解决我的问题或者可能没有正确实现代码.
有任何想法吗?
问题的原因是请求和响应URL不一样.即,当用户输入网站URL并且没有使用HTTPS作为前缀时,将发生重定向循环.
原因是隐藏的,因为如果未经过身份验证或授权,用户会立即重定向到ADFS.
我所要做的就是确保将所有用户请求重定向回HTTPS URL,并删除HTTP绑定.(要么就可以了,要么就好了)
这是我用来确保所有请求都重定向到https的代码.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="Off"/>
<add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
我希望这篇文章很有帮助.
| 归档时间: |
|
| 查看次数: |
1756 次 |
| 最近记录: |