IIS 7 UrlReferrer抛出异常

时间:2011-11-29 08:54:01

标签: asp.net iis-7

当我获得引荐来源网址时,IIS 7会抛出异常。我的代码是这样的:

var referrer = Request.UrlReferrer == null ? null : Request.UrlReferrer.AbsoluteUri;

Application抛出带有错误消息的ArgumentException,

  

“价值不在预期范围内。”

IIS 6中没有问题。

使用“Response.Redirect”

导航页面时会发生此异常

应用程序主页根据当前用户的角色具有Response.Redirect方法。用户主页面抛出此异常。

如何在IIS 7中获取Referrer URL。

谢谢,

1 个答案:

答案 0 :(得分:3)

当我尝试从请求处理中启动的System.Threading.Task访问请求对象时,遇到了类似的问题。 我正在使用该任务来减少响应时间 - 在我的情况下,大多数处理可以在发送请求后执行。 也就是说,我有类似的东西:

public ActionResult SomeAction()
{
    new System.Threading.Task(() => {

        // here I used this.Request.UrlReferrer and got weird ArgumenException error

    }).Start();

    return someActionResultThatDoesntRequireProcessing;
}

我已将UrlReferrer(以及我需要的其他this.Request.stuff)在延迟处理中提取到一个单独的“闭包”变量中(我选择它们来获得非常基本的类型):

public ActionResult SomeAction()
{
    var urlReferrerAbs = this.Request.UrlReferrer.AbsoluteUri;
    var clientAddress = this.Request.UserHostAddress;
    // save other stuff from the request object

    new System.Threading.Task(() => {

        // here I used urlReferrerAbs instead of this.Request.UrlReferrer and the error has gone!

    }).Start();

    return someActionResultThatDoesntRequireProcessing;
}

这对我有用。

相关问题