ASP.NET MVC身份验证Cookie未被检索
|
我很难在具有自定义主体的MVC应用程序中实现“记住我”功能.我把它归结为ASP.NET没有为我检索身份验证cookie.我在Google Chrome中添加了一张快照. >显示在控制器操作中设置并放置在ViewData中以供视图读取的Request.Cookies的结果.请注意,它缺少.ASPXAUTH cookie alt text http://i50.tinypic.com/ibctjd.png 这可能是什么问题?为什么ASP.NET不从cookie集合中读取此值? 我的应用程序使用自定义IPrincipal. BusinessPrincipalBase是一个CSLA对象,它实现了IPrincipal.这是代码: [Serializable()]
public class MoralePrincipal : BusinessPrincipalBase
{
private User _user;
public User User
{
get
{
return _user;
}
}
private MoralePrincipal(IIdentity identity) : base(identity)
{
if (identity is User)
{
_user = (User)identity;
}
}
public override bool Equals(object obj)
{
MoralePrincipal principal = obj as MoralePrincipal;
if (principal != null)
{
if (principal.Identity is User && this.Identity is User)
{
return ((User)principal.Identity).Equals(((User)this.Identity));
}
}
return base.Equals(obj);
}
public override int GetHashCode()
{
return base.GetHashCode();
}
public static bool Login(string username,string password)
{
User identity = User.Fetch(username,password);
if (identity == null || !identity.IsAuthenticated)
{
identity = (User)User.UnauthenicatedIdentity;
}
MoralePrincipal principal = new MoralePrincipal(identity);
Csla.ApplicationContext.User = principal;
Context.Current.User = identity;
return identity != null && identity.IsAuthenticated;
}
public static void Logout()
{
IIdentity identity = User.UnauthenicatedIdentity;
MoralePrincipal principal = new MoralePrincipal(identity);
ApplicationContext.User = principal;
Context.Current.User = identity as User;
}
public override bool IsInRole(string role)
{
if (Context.Current.User == null || Context.Current.Project == null)
{
return false;
}
string userRole = Context.Current.User.GetRole(Context.Current.Project.Id);
return string.Compare(role,userRole,true) == 0;
}
该应用程序还使用自定义成员资格提供程这是代码. public class MoraleMembershipProvider : MembershipProvider
{
public override bool ValidateUser(string username,string password)
{
bool result = MoralePrincipal.Login(username,password);
HttpContext.Current.Session["CslaPrincipal"] = ApplicationContext.User;
return result;
}
#region Non-Implemented Properties/Methods
public override string ApplicationName
{
get
{
return "Morale";
}
set
{
throw new NotImplementedException();
}
}
// Everything else just throws a NotImplementedException
#endregion
}
我不认为这是任何相关的,因为底线是Request.Cookies不返回身份验证cookie.它与cookie的大小有关吗?我听说cookie有大小问题. 更新:问题似乎围绕子域.此站点使用子域托管,cookie域保留为空.有没有人对如何让auth cookie与所有域(例如http://example.com,http://www.example.com和http://sub.example.com)一起使用有任何指示? 解决方法你也检查过这个吗?ASPXAUTH cookie is not being saved 我不确定这是否会导致cookie出现在chrome中但实际上没有传递给浏览器,或者它是否会阻止cookie保存但值得一看. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – 当我将’启用32位应用程序’更改为False时,为什
- asp.net-mvc-4 – ASP.NET MVC 4网站速度问题
- asp.net-mvc – 在没有EF的情况下在appsettings.json中获取
- asp.net – ‘txtName’未声明 由于其保护等级可能无法访问
- asp.net-mvc – ASP.NET MVC,强类型视图,部分视图参数毛刺
- 是否有比ASP.NET成员资格提供程序更现代的会员/安全性实现
- asp.net – 是否有支持请求参数连接的URL构建器?
- 令人敬畏的ASP.NET和C#教程初学者
- asp.net-mvc – JsonSerializer – 使用’N2’格式序列化小
- asp.net – 在ValidationSummary上动态显示bootstrap的周围
- asp.net – 哪个会员提供程序实现存储在web.conf
- 如何为ASP.NET_SessionId cookie设置HttpOnly?
- asp.net – WebFormsMVP的缺点?
- asp.net-mvc-2 – Asp.net Mvc显示String的模板,
- asp.net-core – 使用AspNet Core 2.0进行Google
- asp.net-mvc – 什么时候使用ViewData而不是View
- ASP.NET MVC API 接口验证的示例代码
- asp.net – 可以使用URI模板来匹配URI到路由吗?
- asp.net – 将linq连接到sql datacontext到业务层
- asp.net-mvc – 让System.Web.Optimization在类库
