Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 联合身份验证会话身份验证模块添加声明MVC 5_C#_Cookies_Asp.net Mvc 5_Token_Federated Identity - Fatal编程技术网

C# 联合身份验证会话身份验证模块添加声明MVC 5

C# 联合身份验证会话身份验证模块添加声明MVC 5,c#,cookies,asp.net-mvc-5,token,federated-identity,C#,Cookies,Asp.net Mvc 5,Token,Federated Identity,我需要在登录到第三方系统后向cookie添加声明。我有些了解FederatedAuthentication.SessionAuthenticationModule的工作原理,但我不是100%。我知道您必须将以下内容添加到web配置中: <configuration> <configSections> <!-- For more information on Entity Framework configuration, visit http://go.m

我需要在登录到第三方系统后向cookie添加声明。我有些了解FederatedAuthentication.SessionAuthenticationModule的工作原理,但我不是100%。我知道您必须将以下内容添加到web配置中:

<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <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>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="None" />
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>

  <system.webServer>
    <modules>
      <remove name="WebDAVModule" />
      <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"></add>
    </modules>
  </system.webServer>
我目前拥有它,因此//此处添加声明的地方是以下代码:

var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Role, "User"));
var ci = new ClaimsIdentity(claims);
var cp = new ClaimsPrincipal(ci);
var token = FederatedAuthentication.SessionAuthenticationModule.CreateSessionSecurityToken(
    cp, 
    "BatchSMS",
    DateTime.UtcNow, 
    DateTime.UtcNow.AddDays(1), 
    true);

FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(token);
var索赔=新列表();
添加(新索赔(ClaimTypes.Role,“用户”);
var ci=新的索赔实体(索赔);
var cp=新索赔(ci);
var token=FederatedAuthentication.SessionAuthenticationModule.CreateSessionSecurityToken(
内容提供商,
“批量短信”,
DateTime.UtcNow,
DateTime.UtcNow.AddDays(1),
正确的);
FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(令牌);
然而,我得到一个访问被拒绝的错误。我不知道我是否已经接近做对了。我是否应该添加某种实现接口的类并调用它?我错过了什么

var claims = new List<Claim>();
claims.Add(new Claim(ClaimTypes.Role, "User"));
var ci = new ClaimsIdentity(claims);
var cp = new ClaimsPrincipal(ci);
var token = FederatedAuthentication.SessionAuthenticationModule.CreateSessionSecurityToken(
    cp, 
    "BatchSMS",
    DateTime.UtcNow, 
    DateTime.UtcNow.AddDays(1), 
    true);

FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(token);