Solved

Redirecting to a certain page using C#

Posted on 2014-11-05
5
74 Views
Last Modified: 2015-02-20
I am looking for a way for a user to login to a certain page upon login.  Let me paint a scenario.  Let's say the user wants to go to a certain page on the site, but is not able to until they login, the desired function would be to allow the user to go to the page they selected before they logged in as opposed to the default page.  How can I do that using C# with asp.net?
0
Comment
Question by:VBBRett
5 Comments
 
LVL 20

Accepted Solution

by:
Daniel Van Der Werken earned 167 total points
ID: 40423740
One way to do this is to keep the redirect location in a database table for each user:

Username     RedirectPage
VBBRett         /pages/page01.aspx
Dan7el           /pages/page05.aspx

Open in new window


Then, when the user logs in, read the page they're supposed to go to from the table and redirect to that page.
0
 

Author Comment

by:VBBRett
ID: 40424418
This is not exactly what I was anticipating.  What I mean by my question is the following:

VBBrett typically redirects to members/home.aspx when he logs in, but he thinks to type in members/controlpanel.aspx before he is able to login, so he is immediately faced with the login screen.  After he successfully puts his credentials in, I want him to be redirected to members/controlpanel.aspx since that is where he initially wanted to go before he logged in as opposed to members/home.aspx.  But, if he decides to just go through the default process, he will just be redirected to members/home.aspx.  Does that make sense?  Let me know!  Thanks!
0
 
LVL 11

Assisted Solution

by:louisfr
louisfr earned 167 total points
ID: 40425636
Are you using a Login control?
If so, do not specify a value for the DestinationPageUrl property.

If you're using a FormsAuthentication, there is a GetRedirectUrl method.

You can also look for a ReturnUrl parameter in the query.
0
 
LVL 15

Assisted Solution

by:gladxml
gladxml earned 166 total points
ID: 40427912
If you are not using login control or form authentication

You can mimic the GetRedirectURL process

Basically the previous page before it is redirected to the login has been added as a querystring. you need to code in your method where you check if the person is login or not.

Now if the person credential is correct then you can redirect that person to the previous page which can be taken in the querystring.

If somehow the person go directly to the login page therefore there is no querystring you can redirect him to the default page.

HTH.
0
 

Author Comment

by:VBBRett
ID: 40511235
OK, I am about to try it now with some C# code and will post back what the  result is.  Thank you!
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question