如何设置asp.net认证的属性
我的web.config文件中有以下设置。 如果用户没有登录,它基本上限制了对页面的访问。如果我不想使用asp登录控件或实现成员资格提供程序,我如何告诉’asp loginregister.aspx页面已授权请求如果我想实现自己的登录系统?
谢谢。
validation用户后,设置票证….
Response.Cookies.Add(TicketHelper.CreateAuthCookie(Login1.UserName, userData, Login1.RememberMeSet /*persistent cookie*/));
使用这个助手类……
如果使用登录控件,请在Authenticated事件处理程序中执行此操作。
using System; using System.Web; using System.Web.Security; namespace CustomAuthRepurposingFormsAuth { public static class TicketHelper { /// /// /// /// /// be mindful of the cookie size or you will be chasing ghosts /// /// public static HttpCookie CreateAuthCookie(string userName, string userData, bool persistent) { DateTime issued = DateTime.Now; // formsAuth does not expose timeout!? have to hack around the // spoiled parts and keep moving.. HttpCookie fooCookie = FormsAuthentication.GetAuthCookie("foo", true); int formsTimeout = Convert.ToInt32((fooCookie.Expires - DateTime.Now).TotalMinutes); DateTime expiration = DateTime.Now.AddMinutes(formsTimeout); string cookiePath = FormsAuthentication.FormsCookiePath; var ticket = new FormsAuthenticationTicket(0, userName, issued, expiration, true, userData, cookiePath); return CreateAuthCookie(ticket, expiration, persistent); } public static HttpCookie CreateAuthCookie(FormsAuthenticationTicket ticket, DateTime expiration, bool persistent) { string creamyFilling = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, creamyFilling) { Domain = FormsAuthentication.CookieDomain, Path = FormsAuthentication.FormsCookiePath }; if (persistent) { cookie.Expires = expiration; } return cookie; } }
// formsAuth does not expose timeout!? have to hack around the // spoiled parts and keep moving.. HttpCookie fooCookie = FormsAuthentication.GetAuthCookie("foo", true); int formsTimeout = Convert.ToInt32((fooCookie.Expires - DateTime.Now).TotalMinutes);
表单身份validation确实暴露了.Net 4.0 FormsAuthentication.Timeout.TotalMinutes
超时
如果你不想对.NET系统做任何事情,那将会有点困难。
如果您对某些内容感到满意,只需在登录时使用“FormsAuthentication.RedirectFromLoginPage”设置显示用户登录的cookie。
- .NET 4.0中的MembershipProvider
- asp.net标识中的用户名validation消息问题
- 使用SqlMembership Provider重置后无法使用新密码登录
- 更改成员资格,角色等的默认连接字符串
- 在调用“WebSecurity”类的任何其他方法之前,必须调用“WebSecurity.InitializeDatabaseConnection”方法
- 如何对GUID与LINQ进行不区分大小写的比较?
- 如何从ASP.NET MVC自定义IdentityUser模型获取用户配置文件数据?
- 实现自定义成员资格用户和自定义成员资格
- FormsAuthentication和WebSecurity之间的区别