ASP.NET AJAX Role Application Service – Visual Studio 2008 (Orcas)

The first version ASP.NET AJAX gave us client-side support for two application services – profile and authentication. In Visual Studio 2008 (Orcas), an additional built-in service has been added: roles. If you’ve downloaded Eilon’s ASP.NET AJAX JavaScript Class Browser and installed the beta 2 (or beta 1) version of .NET 3.5, then you’ll find the new service under the Sys.Services namespace:

 

Adding support for the role service

If you’re upgrading an ASP.NET 2.0 web site to .NET 3.5 and want to leverage this new built-in service, you’ll have to make a few minor adjustments to web.config (new web sites in .NET 3.5 will already have these configurations). The first change requires adding the role service to the sectionGroup of the configuration settings:

<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" />
  <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
  <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
  <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" />
</sectionGroup>

Next, you need to enable the service from the list of web services under system.web.extensions:

<system.web.extensions>
  <scripting>
    <webServices>        
      <authenticationService enabled="true" requireSSL = "false"/>         
      <profileService enabled="true" />
      <roleService enabled="true"/>
    </webServices>        
    <scriptResourceHandler enableCompression="true" enableCaching="true" />
  </scripting>
</system.web.extensions>

Interfacing with the service is done through a variable called Sys.Services.RoleService. The actual implementation is an object called Sys.Services._RoleService. The application services in ASP.NET AJAX use this pattern to provide a singleton-like access point. Here is an example of a call to the load and isUserInRole methods of the role service:

function pageLoad(){                          
    loadRoles();                         
}
function loadRoles(){               
    Sys.Services.RoleService.load(onLoadRolesCompleted, onLoadRolesFailed, null);        
}

function onLoadRolesCompleted(result, userContext, methodName){                                        
    if (Sys.Services.RoleService.isUserInRole("Administrator")){
        $get("adminView").style.display = "block";            
    }
}

function onLoadRolesFailed(error, userContext, methodName){
    alert(error.get_message());
}

As an alternative to calling the isUserInRole method, you can also retrieve a comma delimited list of roles for the user from the roles property:

Sys.Services.RoleService.get_roles();

Click here (requires SQL Express) for a working sample that demonstrates the use of all three services.

Published Sunday, July 29, 2007 9:30 PM by davidbarkol
Filed under: , ,

Comments

# ASP.NET AJAXでロールを利用する

Monday, July 30, 2007 1:48 AM by どっとねっとふぁんBlog

ASP.NET AJAX Role Application Service Visual Studio 2008 (Orcas) 以前紹介した以下の記事と合わせて読んでおくといいかな。...

# ASP.NET AJAX Roles and Security

Monday, July 30, 2007 7:44 AM by Michael's Blog

David Barkol writes on his blog about ASP.NET AJAX Role Application Service with Visual Studio 2008

# &raquo; ASP.NET AJAX Role Application Service ??? Visual Studio 2008 (Orcas)

Pingback from  &raquo; ASP.NET AJAX Role Application Service ??? Visual Studio 2008 (Orcas)

# Visual Studio 2008中的ASP.NET AJAX Role Application Service

Wednesday, August 01, 2007 11:48 PM by Dflying Chen

ASP.NETAJAX在目前版本中已经内建了两种ApplicationService:用户身份认证(AuthenticationService)和用户个性化(Profile)(请参考:《在ASP...

# Link Listing - August 2, 2007

Friday, August 03, 2007 12:21 AM by Christopher Steen

Link Listing - August 2, 2007

# AJAX Security - Client Side Validation Is For Usability Only, Not For Security

Wednesday, October 03, 2007 8:29 AM by alik levin's

“As to methods there may be a million and then some, but principles are few. The man who grasps principles

# MSDN Blog Postings &raquo; AJAX Security - Client Side Validation Is For Usability Only, Not For Security

Pingback from  MSDN Blog Postings  &raquo; AJAX Security - Client Side Validation Is For Usability Only, Not For Security

Leave a Comment

(required) 
(required) 
(optional)
(required)