Solved

ASP.Net Login Control Redirect

Posted on 2011-03-21
6
1,130 Views
Last Modified: 2012-05-11
I have a asp.net login control for my site. When a user logs in the page does not redirect anywhere, it just sits at the login page. It's logging you in, as it show your name up top. But I cannot get it to redirect to another page after successful login. How do I get it to redirect tp a certain page? I'm using ASP.Net 4.0.
0
Comment
Question by:dodgerfan
[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
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:khan_webguru
ID: 35184122
Typically, when entering a site, the user starts out at the Default.aspx page. Many times there is a login control on that page or they click on a link that takes them to a login page. I'm can only assume that yours is set up similarly. In that scenario, everything should work fine and your web.config should do what it is supposed to do.

If however, your user is trying to access a page that is restricted (requires logging in), they are automatically redirected to the login page and you will see the "ReturnUrl=" in the URL (Querystring) of the login page. If that is the case, then that will override whatever you have in the web.config so that when they do login successfully they will be sent back to the page that automatically sent them to the login page and not the page you specified in the Web.config. Make sure you don't have your users trying to access a restricted page before they login. Give them a way to log in before they attempt to access a restricted page.

Best way to test this is to set your login page as your default start page by right-clicking on the login page in the solution explorer and selecting "Set as Start Page". Then run the site, log in and see if you get redirected to PatientInformation.aspx.  If everything works like you want, then you need to modify the way the user comes into your site as I outlined above. If you still have trouble, I can probably be of more help if you let me know how you have your users getting to that login control, is it on it's own page and is the PatientInformation.aspx in the root folder of the website? You probably already know this but if your calling ~/PatientInformation.aspx using the "~/", you need to make sure that page is in the root folder of the website. Let me know if that helps. From what it sounds like, your code is correct, it's just the way the user is coming into the site that needs to be fine-tuned.


Any way please for more help browse the following links

http://forums.asp.net/t/1403132.aspx/1?Login+control+FAQ+

http://www.aspnettutorials.com/tutorials/controls/asp4-login-contrls.aspx

Hope this will solve your problem.

Regards,

Asif Ahmed Khan
0
 

Author Comment

by:dodgerfan
ID: 35184269
Thanks for the information. It has helped out some. My web.config had the wrong url for login.aspx. NOw when I log in i goes to the default page. That's a little different from what I was trying to do. When users frist open up the app, it's at the default.aspx page, which is open for any user. They can then click the login link, which takes them to the login.aspx page. Once they click the login button, I want to redirect to the Main.aspx page, not back to the default.aspx page, which it is not doing. All of these pages are in the root folder thus far. Id there a way to do this? Thanks for the help.
0
 
LVL 10

Expert Comment

by:khan_webguru
ID: 35186887
I will try to explain how to use Login control in ASP.Net applications. In The discussion below you will not dig deep into advanced usage of this control or customization of this control. I will discuss simple usage. I will be talking about advanced settings and usage in other articles.

Login control can use either MembershipProvider specified in web.config file, or can explicitly assign Membership provide or you can do custom authenication. To start with basics lets assume that you already have authentication methods implemented using your existing database and you want to leverage that infrastructure with Login control. So what you need to do is, add an handler for OnAuthenticate event handler for your control and authenticate user via that method.


If authentication fails user stays on the same login page. On successful login the user gets redirected to appropriate page. There are couple of ways of specifying the page where user gets sent after successful authentication.


A query string parameter ReturnUrl with a value of URL for redirection is one way. After authentication the implemnetation of Login control will look at this query string parameter and redirect the user to that URL.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Accepted Solution

by:
khan_webguru earned 500 total points
ID: 35186896
Hello Bro,

I will try to explain how to use Login control in ASP.Net applications. In The discussion below you will not dig deep into advanced usage of this control or customization of this control. I will discuss simple usage. I will be talking about advanced settings and usage in other articles.

Login control can use either MembershipProvider specified in web.config file, or can explicitly assign Membership provide or you can do custom authenication. To start with basics lets assume that you already have authentication methods implemented using your existing database and you want to leverage that infrastructure with Login control. So what you need to do is, add an handler for OnAuthenticate event handler for your control and authenticate user via that method.


If authentication fails user stays on the same login page. On successful login the user gets redirected to appropriate page. There are couple of ways of specifying the page where user gets sent after successful authentication.


A query string parameter ReturnUrl with a value of URL for redirection is one way. After authentication the implemnetation of Login control will look at this query string parameter and redirect the user to that URL.

You can set DestinationPageurl property of the control and set the URL of target page in there.

You can handle OnLoggedin event of the control and manually call Response.Redirect to targer page.


Following code snippets show what the attributes on page look like and how OnAuthenticate event handler sets Authenticated value in the event argument.

 
<asp:login id="ctlLogin" runat="server" onauthenticate="OnAuthenticate"
    onloggedin="OnLoggedIn" onloggingin="OnLoggingIn" destinationpageurl="~">
</asp:login>

protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    e.Authenticated = false;
    if (String.Compare(ctlLogin.UserName, "foo", true) == 0 &&
        String.Compare(ctlLogin.Password, "bar", false) == 0)
    {
        e.Authenticated = true;
    }
}		

protected void OnLoggedIn(object sender, EventArgs e)
{
    Response.Redirect("~");
}

Open in new window


Hope this will help you in your problem.

Regards,

Asif Ahmed Khan
0
 
LVL 10

Expert Comment

by:khan_webguru
ID: 35186906
Hello Bro!

I found some more useful link please have a look might be possible something will help yo fix your problem.

http://forums.asp.net/t/1248381.aspx

http://weblogs.asp.net/scottgu/archive/2005/10/18/427754.aspx

http://blog.waltritscher.com/index.php/2006/05/18/tip-aspnet-20-login-control-not-redirecting/

Regards,

Asif Ahmed Khan
0
 

Author Closing Comment

by:dodgerfan
ID: 35193603
Thanks for the help and the links.
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

617 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