question

MattMisner-3316 avatar image
0 Votes"
MattMisner-3316 asked MattMisner-3316 commented

How to capture header referer before authentication redirect

Trying to capture the referer page so that I can redirect the user back to where they came from. Using identity server 4 in the Razor Pages client web application. When a user goes to a page requiring authorize, they sent to identity server 4, then are redirected back to the authorize page. On that authorize page on the client I am unable to know where the user came from originally in the client app. I have read some solutions that use an authorize filter to save the referer in session before being redirected to identity server 4, but I believe it is an MVC solution. When I tried implementing in Razor Pages, the custom authorize filter doesn't get called before I get redirected to identity server 4. Is there a filter or point in the pipeline in Razor Pages where I can save the referer in session before getting redirected to Identity Server 4?

dotnet-aspnet-core-general
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @MattMisner-3316,

From your description, I assume you want to get the "return url" and then redirect to the previous page after authentication. If that is the case, in the previous page, you could get current page url, then pass it via the query string method (put the returnurl at the end of the redirect url (authentication redirect)). Then, in the authentication valid method, after validation, you could check whether the return url is null or not, then redirect to the page. You could refer the following links: Back to previous page - ASP.NET CORE and Working with return url in asp.net core.

0 Votes 0 ·

I was able to pass the returnUrl as asp-route-returnUrl using @Context.Request.Path.
Thanks!

0 Votes 0 ·

Hi @MattMisner-3316,

May I know whether your issue has been solved or not? If not, please share it in here. We can work together to figure it out.

0 Votes 0 ·
Show more comments

0 Answers