1

WIF と、ThinkTecture STS を使用したフェデレーション セキュリティ モデルを使用しています。

http://domain.com/#pageという URL を要求しようとすると、認証後に WIF が正しいページにリダイレクトされません。

wctxruパラメータに/#pathの正しいパスが含まれていません。代わりに、ハッシュとそれ以降のすべてを無視するため、ruパラメータは/になります。ハッシュのない通常の URL は正常に機能します。

これにはワークアウトがありますか、それとも URL のフォーマットが間違っていますか?
助言がありますか?

4

4 に答える 4

3

すぐにリダイレクトするのではなく、JavaScript を発行してリダイレクトを実行することにより、ハッシュ部分を保持できます。JavaScript コードは、window.location.hash を介してハッシュ部分にアクセスし、それを使用して ru を構築できます。

認証されていないユーザーを許可するようにページを構成する必要があります (WIF パッシブ認証が開始されないようにするため)。その後、ページ コードで認証されていないユーザーを処理できます。

アプリケーションの起動コードで FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider イベントをフックできます (例: Web フォームの Global.asax.cs)。

例 (Web フォーム):

public class Global : HttpApplication
{
    protected void Application_Start(object sender, EventArgs e)
    {
        FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider 
        += this.RedirectToIdentityProviderViaJavaScript;
    }

    const string RedirectHtml =
    @"<html>
        <head>
            <script type='text/javascript'>
                function authenticate(url, utcTimeString) {{
                    var ru = window.location.pathname + (window.location.hash || '');
                    var wctx = 'rm=0&id=passive&ru=' + encodeURIComponent(ru) + '&wtc=' + encodeURIComponent(utcTimeString);
                    url += '&wctx=' + encodeURIComponent(wctx);
                    window.location = url;
                }}
            </script>
        </head>
        <body onload=""authenticate('{0}', '{1}');"">
        </body>
    </html>";

    private void RedirectToIdentityProviderViaJavaScript(object sender, RedirectingToIdentityProviderEventArgs e)
    {
        var fam = FederatedAuthentication.WSFederationAuthenticationModule;
        var msg = new SignInRequestMessage(new Uri(fam.Issuer), fam.Realm);
        var stsUrl = msg.WriteQueryString();
        var utcTime = WebPageRoutines.EncodeUtcTimeString(DateTime.Now);
        var html = string.Format(RedirectHtml, WebPageRoutines.JavascriptEncode(stsUrl), WebPageRoutines.JavascriptEncode(utcTime));
        Response.ClearContent();
        Response.Write(html);
        Response.Status = "200 OK";
        Response.End();
    }
}

混合できないことに注意してください。このアプローチでは # パーツのパラメーター。ru は STS リダイレクト (Thinktecture IdentityServer v2) を生き延びますが、WIF は STS からの POST 後の最終リダイレクトでそれを台無しにするようです。

? を配置します。# の後の部分。
http://www.somewebsite.com/page?param=1&other=2#hashbit
は次のようになります:
http://www.somewebsite.com/page#hashbit?param=1&other=2

于 2014-09-19T05:33:14.057 に答える
2

CreateSignInRequest を使用して、web.config からすべてのパラメーターを取得することをお勧めします。クエリ文字列の問題を修正すると思います。MVC を使用した例

        const string redirectHtml =
            @"<!DOCTYPE html>
              <html>
                <head>
                    <meta charset='utf-8'>
                    <script type='text/javascript'>
                        function authenticate(url) {{
                            var ru = window.location.pathname + (window.location.hash || '');
                            window.location = url.replace('REPLACEWITHURL', encodeURIComponent(ru));
                        }}
                    </script>
                </head>
                <body onload=""authenticate('{0}');"">
                </body>
            </html>";

        var authenticationModule = FederatedAuthentication.WSFederationAuthenticationModule;
        var message = authenticationModule.CreateSignInRequest("passive", "REPLACEWITHURL", false);
        var stsUrl = message.WriteQueryString();
        var html = string.Format(redirectHtml, HttpUtility.JavaScriptStringEncode(stsUrl));
        filterContext.Result = new ContentResult { Content = html };
于 2015-04-10T10:37:18.910 に答える