我需要在SSIS包中使用Microsoft.IdentityModel
dll。
在常规C#应用程序中,我会将程序集添加到app.config文件中,如本网站所示adding Microsoft.IdentityModel
但是我不能在SSIS中使用它,因为它们在脚本组件中没有app.config。
我尝试添加app.config并将这些部分添加到app.config但不起作用。
我还尝试为包配置导入.xml文件。
我调试脚本时得到的确切错误是:
"ID7027: Could not load the identity configuration
because no <system.identityModel> configuration section was found."
答案 0 :(得分:1)
我们使用SecurityTokenHandlerCollection handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
来获取处理程序。
我们将其更改为使用
SecurityTokenHandlerCollection collection = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();
token = collection.ReadToken(xmlReader.ReadSubtree());
以下是代码的使用方式
private static SecurityToken ConvertBearerTokenTextToSecurityToken(string tokenText)
{
SecurityToken token = null;
// ConfigSections must be added to App.Config in order for this line to work - this section must be right after the <configuration> node
//<configSections>
// <!--WIF 4.5 sections -->
// <section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
// <section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
//</configSections>
//SecurityTokenHandlerCollection handlers = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.SecurityTokenHandlers;
using (StringReader stringReader = new StringReader(tokenText))
{
using (XmlTextReader xmlReader = new XmlTextReader(stringReader))
{
if (!xmlReader.ReadToFollowing("Assertion"))
{
throw new Exception("Assertion not found!");
}
SecurityTokenHandlerCollection collection = SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection();
token = collection.ReadToken(xmlReader.ReadSubtree());
}
}
return token;
}