Iis 来自DotNetOpenAuth的错误消息';当传入HttpRequestWrapper时,将返回ReadAuthorizationRequest

Iis 来自DotNetOpenAuth的错误消息';当传入HttpRequestWrapper时,将返回ReadAuthorizationRequest,iis,httprequest,dotnetopenauth,Iis,Httprequest,Dotnetopenauth,我在OAuth控制器中为我的Authorize方法提供了一个自定义授权过滤器。当授权筛选器注意到用户已登录时,它将当前OAuth请求填充到会话中,并将其发送以登录 登录后,在my/OAuth/Authorize端点中,我检查该请求是否在会话中,而不是立即失败,因为当前请求没有附加授权请求。然后,我使用该请求对象调用授权服务器 我的授权操作中的代码如下所示: [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)] [ExternalAppAuth

我在OAuth控制器中为我的Authorize方法提供了一个自定义授权过滤器。当授权筛选器注意到用户已登录时,它将当前OAuth请求填充到会话中,并将其发送以登录

登录后,在my/OAuth/Authorize端点中,我检查该请求是否在会话中,而不是立即失败,因为当前请求没有附加授权请求。然后,我使用该请求对象调用授权服务器

我的授权操作中的代码如下所示:

    [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
    [ExternalAppAuthorizeAttribute]
    public ActionResult Authorize() {
        Object requestObject = this.HttpContext.Session["AuthRequest"];
        HttpRequestBase request = null;
        if ((requestObject != null) && (requestObject.GetType() == typeof(HttpRequestWrapper)))
        {
            request = (HttpRequestWrapper)requestObject;
            this.HttpContext.Session.Remove("AuthRequest");
        }
        EndUserAuthorizationRequest pendingRequest = null;
        if (request != null)
        {
            pendingRequest = this.authorizationServer.ReadAuthorizationRequest(request);
        } else
        {
            pendingRequest = this.authorizationServer.ReadAuthorizationRequest();
        }
        if (pendingRequest == null) {
            throw new HttpException((int)HttpStatusCode.BadRequest, "Missing authorization request.");
        }
但是,当在会话中找到并还原请求时,ReadAuthorizationRequest失败。错误消息不是很有用:“值不在预期范围内。”

以下是stacktrace:

[ArgumentException: Value does not fall within the expected range.]
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode) +10
   System.Web.Util.Misc.ThrowIfFailedHr(Int32 hresult) +9
   System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal(String name) +36
   System.Web.Hosting.IIS7WorkerRequest.GetServerVariable(String name) +49
   System.Web.HttpRequest.AddServerVariableToCollection(String name) +22
   System.Web.HttpRequest.FillInServerVariablesCollection() +85
   System.Web.HttpServerVarsCollection.Populate() +36
   System.Web.HttpServerVarsCollection.Get(String name) +42
   System.Collections.Specialized.NameValueCollection.get_Item(String name) +10
   DotNetOpenAuth.Messaging.MessagingUtilities.GetPublicFacingUrl(HttpRequestBase request, NameValueCollection serverVariables) +61
   DotNetOpenAuth.Messaging.MessagingUtilities.GetPublicFacingUrl(HttpRequestBase request) +43
   DotNetOpenAuth.Messaging.Channel.ReadFromRequestCore(HttpRequestBase request) +69
我已经在飞行中检查了我的请求,其中的所有内容看起来都很好:标题、URI等等。我不知道是什么原因导致了这种情况


有人知道为什么会这样吗?或者,如果您有在用户进行身份验证时存储oauth请求的替代建议,我愿意接受这些建议。

结果表明,HttpRequestWrapper上的ServerVariables在调用时引发了异常(现在从堆栈跟踪中可以明显看出)。我相信这是因为请求被过滤器截获后还没有命中控制器操作。我猜ServerVariables是在控制器操作处理请求时设置的

我通过创建一个实现HttpRequestBase的新类来解决这个问题。我将存储的oauth请求和实际请求传递给它,并从oauth请求返回HttpRequestBase中除ServerVariables之外的所有内容的属性,ServerVariables是我从当前请求返回的