Request.Urlreferrer Null

Request.UrlReferrer null?

If you use the standard Membership provider, and set the Authorization for the directory/page, the code will automatically set a query parameter of ReturnUrl and redirect after a successfull login.

If you don't want to use the Membership provider pattern, I would suggest manually doing the query string parameter thing as well. HTTP referrers are not very reliable.

Request.UrlReferrer is coming as null on page refresh

UrlReferrer can't be controlled by your server side code - it just exposes value sent by browser/client along with request. There are plenty of cases that value is not present (initial request/refresh, HTTP/HTTPS transition) so your code must be able to handle this case.

At very least you just need to check for null (you may also need to handle UriFormatException if you need to handle requests from rogue clients in a nice way):

  if (Request.UrlReferrer != null)
{
// run your code that deals with referrer
}

Trying to check if urlreferrer is null

Request.UrlReferrer is null if there is no referrer, which makes your reference to Request.UrlReferrer.AbsolutePath (a property on a null object) throw a null reference exception.

Instead, try;

@if (Request.UrlReferrer == null)

Request.UrlReferrer not giving expected result

It turned out to be my misunderstanding of the referrer policy "strict-origin". It is too restrictive on internal referrals. What I needed was the slightly less strict "same-origin".

You can see this excellent article which explains all.



Related Topics



Leave a reply



Submit