How do I redirect to a page after successful login?

I’m fairly new to web forms development, playing around with a project created using the ASP.NET Web Application template in VS 2010. After the user successfully logs in, I want the user redirected to a page I created. How do I modify my project to redirect the user after login? Any samples / tutorials / etc are greatly appreciated.

Thanks!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

To simply redirect to a new page when your user has logged in, use the DestinationPageUrl property of your login control… assuming you’re using the Login control that is.

If you need to do anything more advanced you can use the OnLoggedIn event handler for your Login control to perform a redirect manually, or add any code for event logging and such.

If you’ve rolled your own login control, and are just using things like text boxes and button controls, then in your Button_Click event, you can just use Response.Redirect("DestinationHere"); to take your users to a new page.

Method 2

After you checked for login:

Response.Redirect("url");

Method 3

I assume you’re using ASP.NET Login control. There’s a DestinationPageUrl property of that control that handles exactly that. If login was successfull user is redirected to URL provided in that property.

Method 4

  <asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Admin/Default.aspx">
</asp:Login>

Go to Properties and Set DestinationPageUrl.

Method 5

Server.Transfer( *url*) ?

(method on HttpServerUtility)

I know next to nothing about ASP.NET, but from my Java web developer daze, redirect is bad because it involves another network round trip to the browser and back when you really just want to continue processing in another page.

And Response.Redirect() really does issue a 302 response code (“try this other url instead”) back to the browser. yuck. XP

Server.Transfer() looks like the java version of Response.Forward()

Method 6

For Sharepoint farm solution development

Page.Response.Redirect("url");

Method 7

The issue with Response.Redirect() is the 302. In some browsers (eg Chrome) this causes the new session cookie to be immediately invalidated.

In other words, using that method to redirect causes the user to no longer be logged in, so you did not accomplish your purpose!.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x