Hi
I am trying to use SPClaimsUtility for au8thenticating my user as per http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.identitymodel.spclaimsutility.authenticateformsuser.aspx .
But I get error 'Microsoft.SharePoint.IdentityModel.SPClaimsUtility' does not contain a definition for 'AuthenticateFormsUser'
in my object browser for the 'Microsoft.SharePoint.IdentityModel.dll I am not able to find the def for this static function.
What could be the possible cause?
Cheers-hemant
we could not solve above problem but I used below mentioned code for FBA authentication finally:
Authenticate returns true or false according to user is authenticated or not .
private SecurityToken GetSecurityToken(string loginName,string psswrd)
{
return SPSecurityContext.SecurityTokenForFormsAuthentication(newUri(SPContext.Current.Site.Url),"memebershipprovidername","roleprovidername",loginName,psswrd);
}
private bool Authenticate(string loginName, string psswrd)
{
bool flag = false;
SecurityToken securityToken = null;
if (loginName==null && psswrd==null)
{
throw new ArgumentException("Please provide username and password");
}
using (new SPMonitoredScope("Retrieve security token and establish session."))
{
securityToken =
this.GetSecurityToken(loginName,psswrd);
if (securityToken == null)
{
flag =
false;
}
else
{
this.EstablishSessionWithToken(securityToken);
flag =
true;
}
}
return flag;
}
internal void EstablishSessionWithToken(SecurityToken securityToken)
{
if (securityToken == null)
{
throw new ArgumentNullException("securityToken");
}
Microsoft.SharePoint.IdentityModel.
SPFederationAuthenticationModule fam = this.Context.ApplicationInstance.Modules["FederatedAuthentication"] asMicrosoft.SharePoint.IdentityModel.SPFederationAuthenticationModule;
if (fam == null)
{
throw new ArgumentException(null, "FederationAuthenticationModule");
}
//Microsoft.SharePoint.Utilities
// .SecurityContext.RunAsProcess(delegate
//{
fam.SetPrincipalAndWriteSessionToken(securityToken,
true, SPSecurityTokenServiceManager.Local.UseSessionCookies);
//});
}
this function is not available in beta version of sharepoint 2010. in licensed version dll , the reference is there.
further the alternative code mentioned above has minor change wrt licensed version of new dll:
fam.SetPrincipalAndWriteSessionToken(securityToken);
instead of
fam.SetPrincipalAndWriteSessionToken(securityToken,
true, SPSecurityTokenServiceManager.Local.UseSessionCookies);
further we may like to have our own custom sign out:-
protected void lnkBtnSignOut_Click(object sender, EventArgs e)
{
HttpContext httpCntxt = HttpContext.Current;
//Signing out
FormsAuthentication.SignOut();
//Request.Cookies.Clear();
// nullifies current context
HttpContext.Current =
null;
//refills current context
HttpContext.Current = httpCntxt;
//abandons user's session
Session.Abandon();
//Clears authentication cookies if present
if (Response.Cookies.Count > 0)
{
if(Response.Cookies["FedAuth"] != null)
Response.Cookies[
"FedAuth"].Expires = DateTime.Now.AddDays(-1);
if (Response.Cookies[".ASPXAUTH"] != null)
Response.Cookies[
".ASPXAUTH"].Expires = DateTime.Now.AddDays(-1);
}
//Redirects to login page
FormsAuthentication.RedirectToLoginPage();
}
Reply 1 by http://social.technet.microsoft.com/profile/shantha%20kumar/?ws=usercard-mini
Hi,
This error occurs because of, you didn't have the Microsoft.SharePoint.IdentityModel.dll as a reference in your project.
If you need that, Search for that dll under installation drive (C:\Windows)
For me, that dll appears under (C:\Windows\Installer\$PatchCache$\Managed\00004109410100000100000000F01FEC\14.0.4763 )
Copy that dll and paste it some where, add this dll as a reference in your project.
I hope, this will help for you.
Shantha Kumar T - MCTS
No comments:
Post a Comment