问题描述
||
ASP.net网页堆栈带有简单成员资格,其中最好的解释是Matthew Osborn的Using SimpleMembership。 SimpleMembership是一个轻量级的用户/登录/成员资格系统,该系统允许cookie用于“记住我”登录目的。我想通过强制cookie为httpOnly并使其成为安全(仅https)cookie来提高cookie的安全性。我怎样才能做到这一点?
更新:@Darin Dimitrov指出,httpOnly仅是会话,这不是我想要的。
解决方法
如果您不使用持久性cookie,则意味着该cookie将不再存储在客户端计算机上,这将使“记住我”功能的全部目的无效。 “ 0” Cookie存储在浏览器的内存中,但仅用于给定的会话。为了提高安全性,请确保将cookie设置为带有安全标志,该标志指示该cookie仅通过加密连接进行传输。
, 如果适合您,我建议您看一下源代码,看看它是如何完成的:
http://aspnetwebstack.codeplex.com/SourceControl/changeset/view/9c98c6e9a150#src%2fWebMatrix.WebData%2fWebSecurity.cs
现在,我已经检查过自己... :)到目前为止,这是它们的外观:
public static bool Login(string userName,string password,bool persistCookie = false)
{
VerifyProvider();
bool success = Membership.ValidateUser(userName,password);
if (success)
{
FormsAuthentication.SetAuthCookie(userName,persistCookie);
}
return success;
}
public static void Logout()
{
VerifyProvider();
FormsAuthentication.SignOut();
}
成员资格提供与System.Web.Security.Membersip大致相同的API,该API实际上在启动时与WebMatrix.WebData.SimpleMembershipProvider交换。
基本上,如果您要使用自定义的auth cookie机制,则必须实现自己的登录和注销逻辑。网上有很多朝着这个方向的样本。
我希望这能有所帮助。
祝好运! :)