Link to home
Start Free TrialLog in
Avatar of rodmjay
rodmjayFlag for United States of America

asked on

FormsAuthentication from non login page

I am trying to create a login system from a page other than login.aspx, as a matter of fact it is the home page itself.  I know that this must be an easy question but ive been working on it for a little while now to no avail.  I need to authenticate the user and redirect to a page.  Simple.  This is not the login.aspx page although there is this page available.

here is the code i am using to no avail, ive tried other things too but they didnt work either

        If Membership.ValidateUser(txtUserName.Text, txtPassword.Text) Then

            If FormsAuthentication.Authenticate(txtUserName.Text, txtPassword.Text) Then
                Response.Redirect("~/Institute/MyInstitute.aspx")
            End If

        End If
ASKER CERTIFIED SOLUTION
Avatar of dtryon
dtryon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rodmjay

ASKER

Your code looks pretty good.  For my scenerio where i still want the login.aspx to be the default login page, i needed to add the following code to enable the home page to use the redirectfromloginpage in the web config

 <authentication mode="Forms">
      <forms loginUrl="login.aspx"
      defaultUrl="~/Institute/MyInstitute.aspx" />  <----- This is where the redirect will go if no request has been made
    </authentication>
Avatar of dtryon
dtryon

Great! Glad I helped a bit.  Glad you found an answer that solved the problem.

Davin