Link to home
Start Free TrialLog in
Avatar of ravl
ravl

asked on

RedirectFromLoginPage refuses to work!

Windows XP Prof.
FormsAuthentication.RedirectFromLoginPage(txtUserID.Text, True) fails to redirect to original URL.

I have text book code as described in the MS MCAD/MCSD self paced training book. I know it works 'cos I've had it working. But now it refuses to work! Can't believe the time I've spent trying to track this down. Now it's driving me crazy! Pls can anyone see a problem?

Redirection to the login page happens OK. The user is validated OK and the cookie gets written OK but the application just stays on the login page.

root webconfig:
<authentication mode="Forms">
            <forms name="freddy" loginUrl="AdminLogin.aspx">
                  <credentials passwordFormat="SHA1">
                  </credentials>
            </forms>
</authentication>

restricted folder webconfig:
<authorization>
        <deny users="*" />
</authorization>

AdminLogin.aspx:
    Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        'authenticate username/password from Users.xml
        If IsUserValid(txtUserID.Text, txtPassword.Text) Then
            FormsAuthentication.RedirectFromLoginPage(txtUserID.Text, True)
        Else
            litStatus.Text = "This userID and password is not authorised, try again."
        End If

        End If
    End Sub

Avatar of AerosSaga
AerosSaga

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        'authenticate username/password from Users.xml
        If IsUserValid(txtUserID.Text, txtPassword.Text) Then
            FormsAuthentication.RedirectFromLoginPage(txtUserID.Text, True)
            Response.Redirect("Mypage.aspx")
        Else
            litStatus.Text = "This userID and password is not authorised, try again."
        End If

        End If
    End Sub

Regards,

Aeros
Avatar of ravl

ASKER

Thanks Aeros. But the Response.Redirect makes no difference, still stuck on the login page. This also ties you to redirection to a specific page.
did you set your web.config for forms authentication?
Avatar of ravl

ASKER

Yes - as I described the root web.config has <authentication mode="Forms">
but did you specify the loginUrl so it knows where to return?
 <authentication mode="Forms" > 
    <forms name="synthesis" loginUrl="login.aspx" timeout="30" />
      </authentication>
Avatar of ravl

ASKER

AerosSaga - if you read the detail I provided you will see that I have indeed done this.
Avatar of ravl

ASKER

The trick, always obvious once someone points it out, dear friends is:

<deny users="?" /> to deny unauthenticated users in the restricted web folder's webconfig.

Eventually found an answer in one of the many web forums through someone who had the same problem.

Sorry I can't allocate any points in this case. But thanks anyway.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

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