0
我已經添加了這些使用,並且已安裝nuget軟件包。爲什麼我不能使用索賠? Visual Studio聲稱無法找到ClaimsIDentity,Claim和ClaimTypes。無法找到類型或命名空間名稱'ClaimsIdentity'
〜/控制器/ AccController.cs
using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
namespace MyProject.Controllers
{
public class AccController : Controller
{
[AllowAnonymous]
[HttpPost]
public ActionResult Login(LoginModel model)
{
if (!ModelState.IsValid)
{
return View();
}
// Don't do this in production!
if (model.Email == "[email protected]" && model.Password == "password")
{
var identity = new ClaimsIdentity(new[] {
new Claim(ClaimTypes.Name, "Ben"),
new Claim(ClaimTypes.Email, "[email protected]"),
new Claim(ClaimTypes.Country, "England")
},
"ApplicationCookie");
var ctx = Request.GetOwinContext();
var authManager = ctx.Authentication;
authManager.SignIn(identity);
return Redirect(GetRedirectUrl(model.ReturnUrl));
}
// user authN failed
ModelState.AddModelError("", "Invalid email or password");
return View();
}
}
}