Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/56.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
Asp.net mvc ASP.NET MVC DotNetOpenAuth是否在验证后获取返回URL?_Asp.net Mvc_Dotnetopenauth - Fatal编程技术网

Asp.net mvc ASP.NET MVC DotNetOpenAuth是否在验证后获取返回URL?

Asp.net mvc ASP.NET MVC DotNetOpenAuth是否在验证后获取返回URL?,asp.net-mvc,dotnetopenauth,Asp.net Mvc,Dotnetopenauth,调用authenticate时,我传递的是查询字符串的返回Url。当开放Id提供程序重定向回相同的操作结果时,返回Url参数为null。在整个通话中保持这种状态的最佳方式是什么 人们是否在会话中存储本地返回Url?下面是正在讨论的方法 [ValidateInput(false)] public ActionResult Authenticate(string returnUrl) { openId = new OpenIdRelyingParty();

调用authenticate时,我传递的是查询字符串的返回Url。当开放Id提供程序重定向回相同的操作结果时,返回Url参数为null。在整个通话中保持这种状态的最佳方式是什么

人们是否在会话中存储本地返回Url?下面是正在讨论的方法

    [ValidateInput(false)]
    public ActionResult Authenticate(string returnUrl)
    {
        openId = new OpenIdRelyingParty();

        IAuthenticationResponse response = openId.GetResponse();

        if (response == null)
        {
            Identifier id;
            if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
            {
                try
                {
                    // at this point we have a return Url
                    return openId.CreateRequest(id).RedirectingResponse.AsActionResult();
                }
                catch (ProtocolException pex)
                {
                    ModelState.AddModelError("", pex.Message);
                    return View("LogOn");
                }
            }
            else
            {
                ModelState.AddModelError("", "Invalid Identifier");
                return View("LogOn");
            }

        }
        else
        {
            switch (response.Status)
            {
                case AuthenticationStatus.Authenticated:
                    FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier, true);
                    // at this point return URL is null

                    var fetch = response.GetExtension<FetchResponse>();
                    string email = string.Empty;
                    if (fetch != null)
                        email = fetch.GetAttributeValue(WellKnownAttributes.Contact.Email);

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        var test = FormsAuthentication.GetRedirectUrl(User.Identity.Name, false);
                        var url = AppHelper.GenerateReturnURL(Request, returnUrl);
                        return Redirect(url);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                case AuthenticationStatus.Canceled:
                    ModelState.AddModelError("", "Canceled at provider");
                    return View("LogOn");
                case AuthenticationStatus.Failed:
                    ModelState.AddModelError("", response.Exception.Message);
                    return View("LogOn");
            }
        }

        return View("LogOn");
    }
[验证输入(假)]
公共操作结果验证(字符串返回URL)
{
openId=新的OpenIdRelyingParty();
IAAuthenticationResponse=openId.GetResponse();
如果(响应==null)
{
标识符id;
if(Identifier.TryParse(Request.Form[“openid_Identifier”],out id))
{
尝试
{
//此时我们有一个返回Url
返回openId.CreateRequest(id.RedirectingResponse.AsActionResult();
}
捕获(协议异常pex)
{
ModelState.addmodeleror(“,pex.Message”);
返回视图(“登录”);
}
}
其他的
{
AddModelError(“,“无效标识符”);
返回视图(“登录”);
}
}
其他的
{
开关(响应状态)
{
案例验证状态。已验证:
FormsAuthentication.SetAuthCookie(response.ClaimedIdentifier,true);
//此时返回URL为空
var fetch=response.GetExtension();
string email=string.Empty;
if(fetch!=null)
email=fetch.GetAttributeValue(WellKnownAttributes.Contact.email);
如果(!string.IsNullOrEmpty(returnUrl))
{
var test=FormsAuthentication.GetRedirectUrl(User.Identity.Name,false);
var url=AppHelper.GenerateReturnURL(请求,返回url);
返回重定向(url);
}
其他的
{
返回重定向到操作(“索引”、“主页”);
}
案例身份验证状态。已取消:
AddModelError(“,”在提供程序处取消”);
返回视图(“登录”);
案例身份验证状态。失败:
ModelState.AddModelError(“,response.Exception.Message”);
返回视图(“登录”);
}
}
返回视图(“登录”);
}
我想出来了:

                        //add returnURL as a callback argument
                    if (!string.IsNullOrEmpty(returnUrl))
                        request.AddCallbackArguments("returnUrl", returnUrl);

是否确定在调用OpenID提供程序之前,表单最初发布到身份验证操作时填充了returnUrl值?肯定。正如我从查询字符串中所期望的那样,它用/Admin填充。当它返回到同一操作时,它为null。您希望它在OpenID提供程序调用后保持不变吗?returnUrl是作为URL查询字符串而不是字段post提交的吗?e、 是的,这是一个合理的方法。