Authenticating Claims User Programmatically
string userProviderName = ConfigurationManager.AppSettings["Membership Provider Name"];
string roleProviderName = ConfigurationManager.AppSettings["Role Manager Name"];
SecurityToken tk = SPSecurityContext.SecurityTokenForFormsAuthentication(
new Uri(SPContext.Current.Web.Url), userProviderName, roleProviderName,
UserNameTxtBx.Text, PasswordTxtBx.Text);
if (tk != null)
{
//try setting the authentication cookie
SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
fam.SetPrincipalAndWriteSessionToken(tk);
//look for the Source query string parameter and use that as the redirection
//string src = "http://general:5678/SitePages/Home.aspx";
string src = SPContext.Current.Site.Url;
if (!string.IsNullOrEmpty(src))
Response.Redirect(src);
}
No comments:
Post a Comment