473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 2332
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
2
by: Eric | last post by:
I am trying to build an app where the stuff in the root directory is open to all, but anything under the Restricted directory requires you to login and I want to use Forms to do it. I'm having...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
7
by: Justin | last post by:
I am trying to password protect a subdirectory using forms authentication. I am using the "Location" tag to specify the directory to be protected. The login.aspx page is in the root directory of...
5
by: V. Jenks | last post by:
Using forms authentication, can I control which pages and/or directories a user would have access to or is that only available with Windows authentication? Thanks!
4
by: =?Utf-8?B?R3V1czEyMw==?= | last post by:
Hi, I created a web site on a remote server. To logon the user must enter a user id and password. The site is uses Forms Authentication. The web config file looks as follows: ...
4
by: Bjorn Sagbakken | last post by:
In a web-application with login creds (user, pwd), these are checked against a user table on a SQL server. On a positive validation I have saved the userID, name, custno and role-settings in a...
5
by: Rory Becker | last post by:
Having now created a Custom MembershipProvider that seems to work correctly with my Logon and ChangePassword controls, I am, as they say, a happy bunny. The next stange is to move on to the...
1
by: Sean | last post by:
Hi, I've taken over a website, which has an admin section that is currently open. I added Forms Authentication to the admin directory with the using the location section in web.config: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.