Quantcast
Channel: Security
Viewing all articles
Browse latest Browse all 4737

Authentication and Authorization Roles

$
0
0

I'm Authenticating the user which works fine. But then I want to give that authenticated user a role so they can access a directory on the website.

For some reason the role is not working.

Web.config   in the directory

<configuration><system.web><authorization><allow roles="Administrator"/><deny users="*"/></authorization></system.web></configuration>

Forms Authentication:

 Dim createPersistentCookie As Boolean = True
        Dim tkt As FormsAuthenticationTicket
        Dim cookiestr As String
        Dim ck As HttpCookie
        tkt = New FormsAuthenticationTicket(1, LoginTokenID, DateTime.Now, DateTime.Now.AddMinutes(2000), createPersistentCookie, "")
        cookiestr = FormsAuthentication.Encrypt(tkt)
        ck = New HttpCookie(FormsAuthentication.FormsCookieName, cookiestr)
        If (createPersistentCookie) Then
            ck.Expires = tkt.Expiration
        End If
        ck.Path = FormsAuthentication.FormsCookiePath
        System.Web.HttpContext.Current.Response.Cookies.Add(ck)

Role added to the user:

Dim roleListArray As String() =  = {"Administrator"}

HttpContext.Current.User =
New GenericPrincipal(HttpContext.Current.User.Identity, roleListArray)

Now the Forms Auth and the adding of the role are in the same Function. After that is completed I send them to the default.aspx page inside the directory I want them to access.

I'm not sure what i'm doing wrong. Any help would be appreciated.


Viewing all articles
Browse latest Browse all 4737

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>