Click here to Skip to main content
15,910,872 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
if (Session["username"] == null)
           {
               Response.Redirect("Signin.aspx");
           }

This is in webform3. This redirects me to my sign in page. After signing in I would like to go straight back to webform3 but my code then takes me to webform 2.

What I have tried:

Is there a spesific way to do it?
or should I save the url inside a session?
Posted
Updated 12-Oct-17 11:15am
Comments
F-ES Sitecore 13-Oct-17 5:21am    
your code says signin but you're talking about webform3 and webform2, it's hard to understand what is going on. This could be a caching issue though, if you have redirected from a certain page and you go back to that page the browser might use the cached version which does the redirect. To see if that is what is happening add a random param to your redirects to get around cache issues

Response.Redirect("SomePage.aspx?r=" + DateTime.Now.Ticks.ToString());
Richard Deeming 13-Oct-17 9:53am    
Why are you re-inventing the wheel? ASP.NET has several perfectly good authentication systems built-in - for example, ASP.NET Identity[^]

1 solution

Typically you would add a parameter to your URL - refer below;
C#
Response.Redirect("Signin.aspx?ReturnToPage=MyPagename");

Then after you have handled the authentication, you can redirect the user to the appropriate page using the following in your code-behind;
C#
Request.QueryString["ReturnToPage"];


Kind Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900