Solved

Redirecting to a certain page using C#

Posted on 2014-11-05
5
71 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now