加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – IdentitySever3重定向多个域的URL

发布时间:2020-12-16 09:32:40 所属栏目:asp.Net 来源:网络整理
导读:特定 IIS中的ASP MVC网站.该站点使用具有impicit流的身份服务器对用户进行身份验证. 它有多个域名.所以该网站是从不同的域名调用的. 例如. foo.com foo.de foo.fr 问题 现在,当我配置我的网站时,我必须设置重定向网址,但这取决于用户来自何处.但是,当应用程
特定

IIS中的ASP MVC网站.该站点使用具有impicit流的身份服务器对用户进行身份验证.

它有多个域名.所以该网站是从不同的域名调用的.

例如.

> foo.com
> foo.de
> foo.fr

问题

现在,当我配置我的网站时,我必须设置重定向网址,但这取决于用户来自何处.但是,当应用程序启动时完成此配置时,我无法根据传入的请求产生影响.

推荐的方法是什么?

public static void Configure(IAppBuilder app)
 {
      app.USEOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
            {
                AuthenticationType = "oidc",Authority = ConfigurationManager.AppSettings["authority"],ClientId = "BlsFrontend",RedirectUri = "http://foo.de",//how to get this dynamically?
                ResponseType = "id_token token",SignInAsAuthenticationType = "Cookies",Scope = "openid profile",

我正在考虑的一件事是使用RedirectToIdentityProvider通知并在请求中重新定位重定向.我测试了它,它适用于我的情况,但这是一个有效/好的方法吗?

RedirectToIdentityProvider = n =>
{
    if (!string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri))
    {
        n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !?
    }
}

解决方法

我发布这个解决方案,因为我没有找到任何其他解决问题的方法,其他一些人也使用了这个解决方案

解决方案是在重定向到身份服务器之前根据请求设置重定向URL.为此,我使用RedirectToIdentityProvider通知

RedirectToIdentityProvider = n =>
{

    if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.Authentication && 
        !string.IsNullOrWhiteSpace(n.ProtocolMessage.RedirectUri))
    {
        n.ProtocolMessage.RedirectUri = n.Request.Scheme + "://" + n.Request.Host.ToString(); //How to make it clean !?
    }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读