加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – IIS 7 UrlReferrer抛出异常

发布时间:2020-12-16 09:50:11 所属栏目:asp.Net 来源:网络整理
导读:当我获得引荐来源网址时,IIS 7会抛出异常.我的代码是这样的: var referrer = Request.UrlReferrer == null ? null : Request.UrlReferrer.AbsoluteUri; 应用程序抛出带有错误消息的ArgumentException, “Value does not fall within the expected range.”
当我获得引荐来源网址时,IIS 7会抛出异常.我的代码是这样的:

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

应用程序抛出带有错误消息的ArgumentException,

“Value does not fall within the expected range.”

IIS 6中没有问题.

使用“Response.Redirect”导航页面时会发生此异常

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

如何在IIS 7中获取Referrer URL.

谢谢,

解决方法

当我尝试从请求处理中启动的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;
}

这对我有用.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读