tags:

views:

26

answers:

2

I am new to .net. I have created a page with login.

When I enter the information and when the username and password match, "My home page" text turns into a hyperlink, when I click the hyperlink it directs me to a profile web-form.

I need to modify the code in such a way that when the login details match the page should be directed to the profile web-form without having to click the hyperlink. I need code for this issue.

Thank You

+1  A: 

You need to do this in your code behind. Attach something along these lines to your login Button click event.

Protected Sub Login_OnClick(ByVal sender As Object, ByVal e As System.EventArgs)  
    If Page.IsValid Then 
        If Membership.ValidateUser(txtUsr.Text, txtPass.Text) Then 
            FormsAuthentication.RedirectFromLoginPage(txtUsr.Text, RememberMe.Checked)  
        Else 
            FailureText.Visible = True 
        End If 
    End If 
End Sub 

Here's a blog post I wrote about it.
http://dotnetblogger.com/post/2010/01/11/ASPNET-Membership-Remember-Me-That-Actually-Works.aspx

Don't forget to set the default redirect in the web.config

<authentication mode="Forms">
  <forms loginUrl="login.aspx" defaultUrl="default.aspx" />
</authentication>

MDSN: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.defaulturl.aspx

rockinthesixstring
+1 for the blog post, as i symphathise with your cause. I wouldn't be caught dead with the ASP.NET Login Controls anymore. I recently found some code where the authentication was handled by a CSS Friendly Adapter for the Login control - using an OnAuthenticate delegate. Ridiculous.
RPM1984
If it's not mission critical information, I simply use OpenID (Like SO). For secure log-ins I still use the built in Authentication, I've just tweaked it slightly.
rockinthesixstring
A: 

You can set this up in the web.config file:

<authentication mode="Forms">
  <forms ... defaultUrl="http://YourURL"  />
</authentication>

Then add a call to FormsAuthentication.RedirectFromLoginPage() in your Login button code.

Xavier Poinas