web analytics
Understanding ASP.NET authorization Options
codeling
Posted: Thursday, March 23, 2017 12:59:44 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 770
Points: 3234

Working with Roles at Run Time

At run time, when users visit your site, they establish an identity, either as a Windows account name or by logging into your application. Information about the logged-in user is available to your application from the User property. When roles are enabled, ASP.NET creates an instance of the RolePrincipal class and adds it to the current request context, it also looks up the roles for the current user and adds them to the pervious created User object so that you can check them.

<roleManager

enabled="true"

cacheRolesInCookie="true"

defaultProvider="RoleManagerAzManProvider"

cookieName=".ASPXROLES"

cookiePath="/"

cookieTimeout="30"

cookieRequireSSL="true"

cookieSlidingExpiration="true"

createPersistentCookie="false"

cookieProtection="All">

The following example shows how to determine whether the current user is in the role of member. If the user is in the role, the code displays a button for members:

if (User.IsInRole("members"))

{

   buttonMembersArea.Visible = True;

}

Sponsor
Posted: Thursday, March 23, 2017 12:59:44 PM
codeling
Posted: Thursday, March 23, 2017 1:09:14 PM

Rank:Advanced Member
Groups: Member
Joined: 12/11/2015
Posts: 770
Points: 3234

Caching Role Information

If a user's browser allows cookies, ASP.NET can optionally store role information in an encrypted cookie on the user's computer. On each page request, ASP.NET reads the cookie and populates the role information for that user from the cookie. This strategy minimizes the need to read role information from the database. If the user's browser does not support cookies or if cookies are disabled, role information is instead cached only for the duration of each page request.

Users browsing this topic
Guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.


© 2017 Digcode.com. All rights reserved.