469,927 Members | 1,737 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

forms authentication

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 RedirectFromLoginPage 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!
Nov 18 '05 #1
2 2102
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.EventArgs e)
{
string name = txtLoginUserNumber.Text;
string password = txtLoginPassword.Text;

if(IsUserAuthenticated(name, password)
{
//This persists the cookie across sessions
//Change to false to have user login each time
FormsAuthentication.RedirectFromLoginPage(name, true);
}
}

private bool IsUserAuthenticated(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.EventArgs)

If (IsUserAuthenticated(name, password) Then
FormsAuthentication.RedirectFromLoginPage(name, true)
End If

End Sub

Private Function IsUserAuthenticated(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********@yahoo.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.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 RedirectFromLoginPage 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!

Nov 18 '05 #2
When the user has already registered and has a persistent cookie on
their machine, how do you test this condition to know whether to send
them to your login page or your logged in page when they return to your
website?
Thanks,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Kris van der Mast | last post: by
reply views Thread by Anonieko Ramos | last post: by
7 posts views Thread by Justin | last post: by
5 posts views Thread by V. Jenks | last post: by
4 posts views Thread by =?Utf-8?B?R3V1czEyMw==?= | last post: by
4 posts views Thread by Bjorn Sagbakken | last post: by
5 posts views Thread by Rory Becker | last post: by
1 post views Thread by Sean | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.