All of this is automagic with .NET. To check for an auth cookie, you need to
make it persist (if you only want them to log in once and then come back to
the site without cookies).
Here is a C# snippet:
private void btnLoginSubmit_ Click(object sender, System.EventArg s e)
{
string name = txtLoginUserNum ber.Text;
string password = txtLoginPasswor d.Text;
if(IsUserAuthen ticated(name, password)
{
//This persists the cookie across sessions
//Change to false to have user login each time
FormsAuthentica tion.RedirectFr omLoginPage(nam e, true);
}
}
private bool IsUserAuthentic ated(string name, string password)
{
//COde here to contact database
//Return true if authenticated
//False if not
//Initially hardcoded to true
return true;
}
VB.NET
--------
Private Sub btnLoginSubmit_ Click(ByRef sender As Object, ByRef e As
System.EventArg s)
If (IsUserAuthenti cated(name, password) Then
FormsAuthentica tion.RedirectFr omLoginPage(nam e, true)
End If
End Sub
Private Function IsUserAuthentic ated(ByVal name As String, _
ByVal password As String) As Boolean
'COde here to contact database
'Return true if authenticated
'False if not
Return True
End Function
Hope this helps. The help file is very good on this one, BTW.
--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
*************** *************** *************** ***
Think Outside the Box!
*************** *************** *************** ***
"mike parr" <mp********@yah oo.co.uk> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
I'm using forms authentication and on my first page I want to check if
the user has a cookie, and if they do I want to authenticate then and
send them to my default page with a greeting, otherwise send them to a
login page.
I've seen a lot of examples on the internet where the user login details
are checked and then RedirectFromLog inPage is used, but I haven't seen
anything on simply authenticating the user and then sending them to a
page of your choosing.
I can check the user is valid against my database and then redirect
them, but they are not authenticated by the application and still can't
view my pages that require authentication.
Can anybody tell me how this is done?
Thanks,
Mike
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!