IIS 7 UrlReferrer exception throws

When I get the referrer URL, IIS 7 throws an exception. My code is:

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

The application throws an ArgumentException error message with an error message,

"The value is not in the expected range."

IIS 6 has no problems.

This exception occurs when a page is moved using "Response.Redirect"

On the main page of the application there is a Response.Redirect method in accordance with the role of the current user. This exception has been selected on the user's homepage.

How to get the Referrer URL in IIS 7.

Thanks,

+4
source share
1 answer

When trying to access the request object from the System.Threading.Task object that was launched in processing the request, a similar problem occurred. I use a task to reduce response time - in my case, most of the processing can be done after sending the request. That is, I had something like:

 public ActionResult SomeAction() { new System.Threading.Task(() => { // here I used this.Request.UrlReferrer and got weird ArgumenException error }).Start(); return someActionResultThatDoesntRequireProcessing; } 

I pulled UrlReferrer (and other this.Request.stuff that I needed) in the delayed processing) into a separate "close" variable (I selected them to have the most basic types):

 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; } 

It worked for me.

+3
source

Source: https://habr.com/ru/post/1383595/


All Articles