asp.net - IIS 7 UrlReferrer 抛出异常

标签 asp.net iis-7

当我获取引荐网址时,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;
}

这对我有用。

关于asp.net - IIS 7 UrlReferrer 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8308031/

相关文章:

c# - ASP.Net 中的自定义角色提供程序是否为使用 Windows 身份验证的每个用户实例化?

IIS7认证问题

visual-studio-2010 - 在根目录而不是子目录中调试 VS2010 网站

asp.net-mvc - IIS7,SQL 2008和ASP.NET MVC安全性

css - 网站发布时提供的 MVC 应用程序模板圆 Angular 消失

.net - 免费工具或库,可在.Net中将Tiff文件转换为pdf

c# - "not-null property references a null or transient value"删除对象时

html - 使用 ASP 重复器创建一个 HTML 表格,水平重复

asp.net - 使用 Windows IIS 删除只读权限

asp.net - 注册外部登录时 CreateUserAsync 失败