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