Re: forms authentication

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Cowboy (NoSpamMgbworld_at_comcast.netNoSpamM)
Date: 05/17/04


Date: Mon, 17 May 2004 09:17:53 -0500

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" <mparr_1972@yahoo.co.uk> wrote in message
news:%23QjBtSAPEHA.3708@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!


Relevant Pages

  • Re: Forms Auth keeps going to logon page
    ... string password = PasswordText.Text; ... You do not set the cookie for authentication using Response.Cookies. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: Forms authentication cookie handling question (C#)
    ... I also replaced all of my ticket authentication code with the ... // Username and or password not found in our database... ... LoginControl's default code logic to generate authentication cookie. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Forms Authentication
    ... The DNS entry for my domain was not set corrretly, ... This should have overcome the cookie ... authentication ticketis not correctly set to the domain your ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Forms authentication cookie handling question (C#)
    ... programmatically generate forms authentication ticket and set it in ASP.NET ... You use the Login control's "Authentication" event to do the user ... LoginControl's default code logic to generate authentication cookie. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: authentication cookie vs session cookie
    ... level of using authentication cookies on the client machines. ... authentication cookie on a manager's machine is stolen and used on a client ... > session variables as it relies on the session cookie that ASP.NET sends to ...
    (microsoft.public.dotnet.framework.aspnet.security)