Gal Ratner
Gal Ratner is a Techie who lives and works in Los Angeles. Follow galratner on Twitter Google
Forms authentication with Client Application Services

System.Web.ClientServices.Providers contains client service providers that support remote access to the Microsoft Ajax authentication, roles, and profile services.
Today we will be looking at a common use case and solve it using client application services. We have a remote website containing the default ASP.NET membership provider and we need to access it from another website in order to log on a remote user.
In order to enable client application services in the remote site we need to change the web.config

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


In our local website we need to define the remote authentication service

<membership defaultProvider="ClientAuthenticationMembershipProvider" userIsOnlineTimeWindow="120">
<providers>
<clear />
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="http://www.myremotesite.com/AppServices/Authentication_JSON_AppService.axd" credentialsProvider="" />
</providers>
</membership>
<roleManager enabled="true" cacheRolesInCookie="false" cookieTimeout="30" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All" defaultProvider="ClientRoleProvider" createPersistentCookie="false" maxCachedResults="25">
<providers>
<clear />
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="http://www.myremotesite.com/AppServices/Role_JSON_AppService.axd" cacheTimeout="86400" />
</providers>
</roleManager>


In order to validate user credentials and log the remote user to our local website we need to use ClientFormsAuthenticationMembershipProvider

public static void ValidateUser(string userName, string password)
{
try
{
              ClientFormsAuthenticationMembershipProvider provider = (ClientFormsAuthenticationMembershipProvider)System.Web.Security.Membership.Providers["ClientAuthenticationMembershipProvider"];
if (provider.ValidateUser(userName, password))
FormsAuthentication.RedirectFromLoginPage(userName, true);
}
catch (WebException e)
{
throw new BusinessLayerException("Unable to access the remote service.", e);
}
}


Now the remote user is logged into the local system. Client Application Services was initially created to assist desktop applications with remote authentication, but, will work great with websites too.

 


Posted 25 Jan 2011 1:14 PM by Gal Ratner
Filed under:

Powered by Community Server (Non-Commercial Edition), by Telligent Systems