Sorry to reply to this after a few days - I was on vacation.

Dean, I tried this and it does not work. I have added the
FormsAuthentication.SetAuthCookie(username, False)to the login code and the
user.intentity.name is still blank.

-----Original Message-----
From: Dean Fiala [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 19, 2004 11:51 PM
To: [EMAIL PROTECTED]
Subject: RE: [AspNetAnyQuestionIsOk] Role-based authorization with Forms
Authentication

When using forms authentication HttpContext.Current.User is set by reading
the FormsAuthenticationTicket (FAT) from the request.

If you haven't created the FAT and added it to the response either manually
or by using FormsAuthentication.SetAuthCookie, ASP.NET will not have the
info to recognize the user.  Add something like this to your login code and
you should be all set....

(username, False)

HTH,


Dean Fiala
-----------------------------
Very Practical Software, Inc.
http://www.vpsw.com/links.aspx



-----Original Message-----
From: Gurmeet Kohli [mailto:[EMAIL PROTECTED]
Sent: Thursday, August 19, 2004 10:40 AM
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] Role-based authorization with Forms
Authentication




Hello Everyone,
I am trying to implement role-based authorization with Forms Authentication
and running into a problem.

I have created a login page where the user enters the username and password.
After the user is authentication, I run a procedure in the global.asax file
in the AuthenticateRequest event handler. In this procedure, I am trying to
grab the roles from a table. But the query does not return any values! I
know the user is authenticated cause the menu that displays the roles is
empty. So the user does get to the .aspx forms.

On debugging I have noticed that the Context.User.Identity.Name is empty. I
am using the username that the user enters in the login form. My code is as
follows:

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data.OleDB" %> <%@ Import
Namespace="System.Security.Principal " %>

<script language="VB" runat="server">

Sub Application_AuthenticateRequest(sender as object, e as EventArgs)
        Dim strConnect as string =
ConfigurationSettings.AppSettings("HealthyVision")
        Dim Conn as OLEDBConnection
    Dim Rdr as OLEDBDataReader
        Dim CmdSelect as OLEDBCommand
    Dim strSQL as string
        Dim rolelist as New Arraylist

        If request.isAuthenticated Then
                'determine the user's role
                Conn=New OLEDBConnection(strConnect)
        Conn.Open()

                'Query to get Applications info from database
            strSQL="SELECT tbl_group.group_name FROM (tbl_User INNER JOIN
tbl_roles ON tbl_User.Userid = tbl_roles.User_id) INNER JOIN tbl_group ON
tbl_roles.Group_id = tbl_group.group_id WHERE
(((tbl_User.Username)[EMAIL PROTECTED]))"


                CmdSelect=New OLEDBCommand(strSQL,Conn)
                CmdSelect.Parameters.add("@username",
Context.User.Identity.Name)
            Rdr=CmdSelect.ExecuteReader()
                While rdr.read()
                        rolelist.Add(rdr("group_name"))
                End While
                Rdr.close()

                'convert the rolelist Arraylist to a string array
                Dim rolelistArray as string() =
rolelist.toArray(gettype(string))

                'Add roles to the user principal
                HttpContext.Current.User = New
GenericPrincipal(User.Identity, roleListArray)

        End if
End Sub
</script>





Yahoo! Groups Links









------------------------ Yahoo! Groups Sponsor --------------------~--> Make
a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links



 



------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to