Pal
Pal

Reputation: 183

Redirect to previous page URL in asp.net core using MVC - c#

I searched around and found some are suggesting to use following line. But this gets me current Url and not the previous page url.

Request.Headers["Referer"].ToString();

I tried to access previous url using below command but getting the error saying Http request does not contain definition for UrlReferrer

Request.UrlReferrer.ToString();

Also tried using Current like this

HttpContext.Current

but still getting the error saying http request does not contain definition for current. Also tried "System.Web.HttpContext.Current" yet receiving error. What am I missing here?

Upvotes: 2

Views: 3411

Answers (1)

Mehrdad
Mehrdad

Reputation: 1723

You should pass your current location when you are navigating to next location, something like returlurl in login. There is no any built-in feature for this purpose.

<a href="/nexlocation?returnurl=currenturl">my link</a>

Upvotes: 2

Related Questions