Tôi đang gặp khó khăn khi thực hiện chức năng "Nhớ tôi" trong ứng dụng MVC với hiệu trưởng tùy chỉnh. Tôi đã đun sôi nó xuống để ASP.NET không lấy cookie xác thực cho tôi. Tôi đã bao gồm ảnh chụp nhanh bên dưới từ Google Chrome.Cookie xác thực MVC ASP.NET không được truy xuất (CẬP NHẬT)
Hiển thị kết quả của Request.Cookies được đặt trong hành động điều khiển và được đặt trong Chế độ xem cho chế độ xem để đọc. Lưu ý rằng nó thiếu cookie .ASPXAUTH
Hiển thị kết quả từ công cụ nhà phát triển Chrome. Bạn có thể thấy rằng .ASPXAUTH được bao gồm ở đây.
alt text http://i50.tinypic.com/ibctjd.png
Có ai biết những gì vấn đề có thể có mặt ở đây? Tại sao ASP.NET không đọc giá trị này từ bộ sưu tập cookie?
Ứng dụng của tôi sử dụng IPrincipal tùy chỉnh. BusinessPrincipalBase là một đối tượng CSLA mà chúng ta thực hiện IPrincipal. Đây là mã cho rằng:
[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;
}
Ứng dụng này cũng sử dụng nhà cung cấp tư cách thành viên tùy chỉnh. Đây là mã cho điều đó.
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
}
Tôi không nghĩ rằng bất kỳ điều này liên quan vì dòng dưới cùng là Request.Cookies không trả lại cookie xác thực. Nó có liên quan đến kích thước của cookie không? Tôi nghe nói có vấn đề với kích thước của cookie.
CẬP NHẬT: Dường như vấn đề xoay quanh tên miền phụ. Trang web này đã được lưu trữ với tên miền phụ và miền cookie được để trống. Có ai có bất kỳ gợi ý nào về cách tôi có thể nhận cookie xác thực để làm việc với tất cả các miền (ví dụ: http://mydomain.com, http://www.mydomain.com và http://sub.mydomain.com)?
Bạn có thể đăng mã bạn đang sử dụng trong quá trình đăng nhập của người dùng không? Bạn chỉ sử dụng công cụ được xây dựng trong FormsAuthentication, mà không cần sử dụng nhà cung cấp? Hoặc, bạn có đang sử dụng nhà cung cấp tùy chỉnh của riêng mình không? – sestocker
Trong lần đăng nhập đầu tiên, giá trị nào được liên kết với cookie (đặc biệt là hết hạn)? – sestocker
Đây là những gì cookie trông giống như: http://i50.tinypic.com/npm26c.png –