Solved

Redirecting to a certain page using C#

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

Accepted Solution

by:
Daniel Van Der Werken earned 167 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

11 Experts available now in Live!

Get 1:1 Help Now