Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在asp.net中传递查询字符串参数?_C#_Azure_Acs - Fatal编程技术网

C# 如何在asp.net中传递查询字符串参数?

C# 如何在asp.net中传递查询字符串参数?,c#,azure,acs,C#,Azure,Acs,我正在使用访问控制服务(ACS)。我使用以下代码获取了我为应用程序设置的所有标识提供程序(ip): public ActionResult IdentityProviders(string serviceNamespace, string appId) { string idpsJsonEndpoint = string.Format(Global.IdentityProviderJsonEndpoint, serviceNamespace, appId);

我正在使用访问控制服务(ACS)。我使用以下代码获取了我为应用程序设置的所有标识提供程序(ip):

    public ActionResult IdentityProviders(string serviceNamespace, string appId)
    {
        string idpsJsonEndpoint = string.Format(Global.IdentityProviderJsonEndpoint, serviceNamespace, appId);
        var client = new WebClient();
        var data = client.DownloadData(idpsJsonEndpoint);

        return Content(Encoding.UTF8.GetString(data), "application/json");
    }
当用户点击登录链接时,上面的代码使用ajax调用,获取IP并在jQueryUI对话框中显示它们。当用户单击任何一个ip进行登录时,浏览器将重定向到所选的ip登录页面。成功登录后,控件返回到我设置为returnUrl的控件。到目前为止,一切正常

现在我要做的是将一些值传递给identity provider(ip)登录页面,并希望在我的returnUrl控制器中返回这些值。为此,我搜索并了解到有一个名为
wctx
的查询字符串参数,我们可以在返回url处设置并获取该参数的值。但是我不知道怎么做。有人能告诉我怎么才能做到这一点吗

这相对(相当)容易

列出IDP的URL如下所示:

https://[your_namespace].accesscontrol.windows.net:443/v2/metadata/IdentityProviders.js?protocol=wsfederation&realm=[your_realm]&reply_to=[configured_return_url_for_your_rp]&context=&request_id=&version=1.0&callback=

这是对身份提供者列表的最完整请求。您可能会遗漏一些变量(例如
上下文
,或
回复
),但我显示的是完整的请求

现在你有两个选择:

  • 包括您自己的
    回复到
    参数。它必须在配置的领域中。所以如果你的领域是
    https://www.mygreatapp.com/
    ,您的默认返回URL可能类似于
    https://www.mygreatapp.com/returnUrl/
    (如果处理ACS响应的控制器是
    returnUrlController
    。现在,您可以安全地将
    reply\u改为
    https://www.mygreatapp.com/returnUrl/?foo=bar
    ,只需确保对查询字符串进行URL编码即可

  • 使用
    context
    参数。使用它更安全,我建议使用它。现在,获取IDP列表的URL如下:

    https://[your_namespace].accesscontrol.windows.net:443/v2/metadata/IdentityProviders.js?protocol=wsfederation&realm=[your_realm]&reply_to=[configured_return\u url\u for_your_rp]&context=[your_自定义字符串\u值,\u您甚至可以加密]&request_id=&version=1.0&callback=/code>

请注意,现在IdP请求列表中存在
上下文
值([您的自定义字符串值,您可以加密它])。在returnUrl处理程序控制器中,您可以使用类似(或等效)以下代码检查它:

if (ControllerContext.HttpContext.Request.Form["wresult"] != null)
            {
                // This is a response from the ACS - you can further inspect the message if you will
                SignInResponseMessage message =
                    WSFederationMessage.CreateFromNameValueCollection(
                    WSFederationMessage.GetBaseUrl(ControllerContext.HttpContext.Request.Url),
                    ControllerContext.HttpContext.Request.Form)
                    as SignInResponseMessage;

                if (!string.IsNullOrWhiteSpace(message.Context))
                {
                    // do whatever you want with the context value
                }
            }
在处理来自ACS的
信号应答
时,您可能需要执行任何/更多附加检查