By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,660 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,660 IT Pros & Developers. It's quick & easy.

forms authentication

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.