Dooie
Dooie

Reputation: 1669

Handling return URLs with ASP.NET Web Forms and Routes

I have an ASP.NET web forms application (not MVC) set up utilising routes which are defined in my Global.asax file like so;

routes.Add("Login", New Route("login", New CustomRouteHandler("~/authenticate.aspx")))
routes.Add("AdditionalInfo", New Route("additional-information", New CustomRouteHandler("~/secure/additionalInfo.aspx")))

At points throughout the application it is a requirement that the user be authenticated which would simply redirect them to the login screen.

The problem I have is how would I then redirect them back to the point where authentication was required? With bog standard url's i would do something like;

http://www.site.com/login.aspx?returnURL=someReturnURL

Is it even possible with routes in web forms?

Upvotes: 2

Views: 2889

Answers (2)

A.Moshayyedy
A.Moshayyedy

Reputation: 117

Usually when user clicks on log-in button, the URL doesn't change. So you still can read the data using 'Request.QueryString["returnURL"];'

Upvotes: 0

Kapil Khandelwal
Kapil Khandelwal

Reputation: 16144

Retrieve the QueryString Parameter on Page_Load Event & save it in

ViewState["returnURL"] = Request.QueryString["returnURL"];

Then, in button click event do the redirection on successfull authentication:

Response.Redirect(ViewState["returnURL"].ToString());

Upvotes: 2

Related Questions