以下是类库帮助类的引用
using System; using System.Collections.Generic; using System.Linq; using System.Security.Principal; using System.Text; using System.Threading.Tasks; using System.Web; using System.Web.Security; //引用System.Web.ApplicationServices namespace StudentManageSys.Common { public class MyFormsPrincipal<TUserData> : IPrincipal where TUserData:class,new() { public IIdentity Identity { get; private set; } public TUserData UserData { get; private set; } public MyFormsPrincipal(TUserData userData) { Identity=new FormsIdentity } public bool IsInRole(string role) { throw new NotImplementedException(); } } }
以下是类库添加的引用
已经添加了
using System.Web;
using System.Web.Security;
但是还是没用
求大神帮忙解答一下为什么FormsAuthenticationTicket 和FormsIdentity找不到定义!
Build时报找不到定义这个错吗?
FormsAuthenticationTicket、FormsIdentity是在using System.Web.Security里的,你可以Clean下Solution再Build。
如果要做身份合法性验证可以用下面这句。
bool autenticated = HttpContext.Current.User.Identity.IsAuthenticated;
MVC中利用”特性“进行身份验证及cookie过期处理解决方案http://www.cnblogs.com/kejie/p/6015073.html
var id = HttpContext.Current.User.Identity as FormsIdentity;