Solved

Redirecting to a certain page using C#

Posted on 2014-11-05
5
76 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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