首页 新闻 会员 周边

asp.net mvc的forms验证时 想写一个公共类创了一个类库 用于forms验证 结果FormsAuthenticationTicket 和FormsIdentity找不到定义!不知道该添加哪些命名空间

0
悬赏园豆:30 [待解决问题]

以下是类库帮助类的引用

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找不到定义!

又是没有bug的一天的主页 又是没有bug的一天 | 初学一级 | 园豆:149
提问于:2017-02-27 14:19
< >
分享
所有回答(2)
0

 

 

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

 

~扎克伯格 | 园豆:1923 (小虾三级) | 2017-02-27 15:01
0

  var id = HttpContext.Current.User.Identity as FormsIdentity;

pengbg | 园豆:13 (初学一级) | 2017-03-21 16:08
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册