Thanks
Venkat
This code goes in the global.asax.
(don't forget to import required namespaces)
<script language="vb" runat="server" Debug="true" >
Public sub Application_OnAuthenticateRequest( src as Object, e as EventArgs)
if (not(HttpContext.current.User is Nothing)) then
if Httpcontext.current.User.Identity.AuthenticationType = "Forms" then
Dim id as FormsIdentity
id = httpContext.Current.user.Identity
Dim Roles1(1) As String
Roles1(0) =
getRole(Httpcontext.current.User.Identity.Name.ToString())
HttpContext.Current.User = new GenericPrincipal(id,Roles1)
End if
End if
End sub
public function GetRole(uid as string) as String
Dim SQLCn as SQLConnection
Dim SQLCmd as SQLCommand
Dim SQlDr as SQLDataReader
SQLCn = new
SQLConnection("server=venkatc;uid=sa;pwd=chilakala;database=Pubs;")
SQLCmd = new SQLCommand("Select userRole from users where alias = '" & uid
& "'", SQLCn)
SQLCn.Open()
SQLDr= SQLcmd.ExecuteReader()
while (SQLDr.Read())
GetRole=SQLDr.Item("userRole")
End While
SQLCn.Close()
End function
</script>
"Venkat Chilakala" <venkat_c...@microsoft.com> wrote in message
news:gAcztC4...@cppssbbsa01.microsoft.com...
The thing to remember here is that the underlying protocol is HTTP and this
is a stateless protocol. This means, in the Microsoft environment, that for
each request, you must rebuild the execution and session environment for
your web application.
Setting the principal in your login page is not going to matter because the
principal is going to be reset in the next request. The
FormsAuthentication.RedirectFromLoginPage() method is going to create an
encrypted cookie with the user name. At the beginning of each request,
ASP.NET will decrypt this cookie and will reset the HttpContext.Current.User
property with the information from the cookie. This means that all of the
role information will be erased.
To implement role-based security, you must implement the
Global.Application_OnAuthenticateRequest() event. ASP.NET will invoke this
event handler prior to executing the request and you can use it to set the
security information. Look at the sample code for the portal at
http://www.ibuyspy.com. What they do is create an encrypted cookie
containing a list of the roles that the user is granted. For each request,
they decrypt the list of roles stored in the cookie, and build a new
GenericPrincipal(), like you are doing in your login page.
After Application_OnAuthenticateRequest() runs, the roles will be set and
you can use role-based security on your web pages.
"Hemant Sathe" <hks...@hotmail.com> wrote in message
news:uEO#yOUKBHA.936@tkmsftngp05...