相关疑难解决方法(0)

AuthenticationManager类中不存在AuthenticationManager.SignIn()

我正在尝试使用AuthenticationManager该类中的方法SignIn();

我是这样做的:

AuthenticationManager.SignIn(identity);
Run Code Online (Sandbox Code Playgroud)

但它说那里SignIn不存在......

通往的路径AuthenticationManager是:

System.Net.AuthenticationManager
Run Code Online (Sandbox Code Playgroud)

我在这里遗漏了什么吗???

编辑:这是控制器的迷你版本:

using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
using System;
using System.Linq;
using System.Security.Claims;
using System.Web.Mvc;
using WebApplication2.Models;
using WebApplication2.ViewModels;

[HttpPost]
[ActionName("Login")]
public ActionResult Login(LoginViewModel model)
{
    if (ModelState.IsValid)
    {
        string userName = (string)Session["UserName"];
        string[] userRoles = (string[])Session["UserRoles"];

        ClaimsIdentity identity = new ClaimsIdentity(DefaultAuthenticationTypes.ApplicationCookie);

        identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, userName));

        userRoles.ToList().ForEach((role) => identity.AddClaim(new Claim(ClaimTypes.Role, role)));

        identity.AddClaim(new Claim(ClaimTypes.Name, userName));

        AuthenticationManager.SignIn(identity);
        return RedirectToAction("Success");
    }
    else
    {
        return View("Login",model);
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:出现新错误:

The following errors …
Run Code Online (Sandbox Code Playgroud)

c# asp.net authentication asp.net-mvc

7
推荐指数
1
解决办法
6703
查看次数

标签 统计

asp.net ×1

asp.net-mvc ×1

authentication ×1

c# ×1