Can't Create Session
-
08-02-2021 - |
質問
I am trying to update a custom authentication page from SharePoint 2010 to 2013. It basically takes credentials from a CAC card and creates them a user account in FBA if they didn't already have one giving them visitor rights. It then creates a Security Token and establishes a session in the browser with that token.
All of this worked fine in 2010, but I have been stuck on this last piece trying to upgrade for 2013. I can create SPFederationAuthenticationModule object called fam, but whenever I try to use it I get an error asking for the base class for SPFederationAuthenticationModule which is WSFederationAuthenticationModule.
ERROR: The type 'WSFederationAuthenticationModule' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
using System;
using System.Web;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Configuration;
using System.Web.Security;
using Microsoft.SharePoint.IdentityModel;
using System.IdentityModel.Tokens;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Utilities;
using CACAuthentication.Classes;
using Microsoft.IdentityModel;
private void EstablishSessionWithToken(SecurityToken securityToken)
{
if (null == securityToken)
{
throw new ArgumentNullException("securityToken");
}
SPFederationAuthenticationModule fam = SPFederationAuthenticationModule.Current;
if (fam == null) //**************ERRROR HERE ON fam*******************//
{
throw new ArgumentException(null, "FederationAuthenticationModule");
}
fam.SetPrincipalAndWriteSessionToken(securityToken, SPSessionTokenWriteType.WriteSessionCookie);
}
解決
As I was writing this I realized the problem after spending all day trying to figure it out. There isn't a local copy of the Microsoft.Identity.dll. I thought I had referenced it, but I had referenced the Microsoft.SharePoint.IdentityModel and the System.IdentityModel. You have to install Microsoft.Identity via NuGet. Since I had already written the question I figured I would go ahead and post it so others can avoid this bonehead mistake.