请问大家做用户权限验证的时候,是用 ASP.NET的Forms验证 还是传统的 COOKIE+SESSION的验证 1、请问大家做用户权限验证的时候,是用 ASP.NET的Forms验证 还是传统的 COOKIE+SESSION的验证2、ASP.NET的Forms验证能做到 COOKIE+SESSION同样的效果吗?比如用户登陆后不关IE永不下线,定义到某个用户是否有添加、删除、审核权限等。谢谢!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 权限验证?权限一般是存到数据库中的吧,需要验证吗?如果说是用户登陆验证的话,一般是都用到,asp.net验证控件+服务器端的验证(如用户名、密码什么的) TO:lr2651(戎 Waiting For Star)不是这意思啊,就是你做后台的时候,不是需要验证到后台这个用户是不是具有管理员权限吗,这个时候,你是怎么判断的呢,根据SESSION?还是什么呢? 我一般用SESSION,但上周五参加Microsoft两岸三地的讨论会,Mivrosoft的工程师不建议这样做,他们说让用验证控件,但没有说具体怎么实现。 在数据库中用一个字段作为标识,然后在通过密码和帐号验证后产生Session! 验证控件??是不是ASP.NET的FORM验证啊? Forms验证就可以了。对于什么权限控制,一般用数据库。 没有人用windows域验证吗?跟登陆机器的用户名走的,一般企业用这个。 ASP.NET的Forms验证好,安全性高,由IIS控制,减低编译器负荷。不要再用asp那种老掉牙的方法了 用FORM,感觉比SESSION效率更高 各位大哥有C# 中Forms验证的实例吗,供小弟参考一下,谢谢! 用asp.net一般都是用forms验证吧,用cookie和session体验不了asp.net的特性,再说很不方便。 forms验证。。哪有没有经给一个小实例啊 验证的话可以用Validating事件+正则表达式,控件可以用ErrorProvider控件,纯属个人意见 胡扯,Form验证不过是微软封装的基于Session的验证罢了。与IIS有什么关系,还有,效率会更高?!只不过是登陆注销等代码微软帮你写了而已。Form验证只是更傻瓜,不灵活。楼主如果自己很清楚该怎么做,完全没必要用Form验证把自己都给搞糊涂了。 哈哈,还是 Ivony() 有见地! 谢谢Ivony() 啊,那为什么还有那么多人说FORM验证好啊.是盲目的追赶新技术么?继续请教啊!!!@@ 呵呵,偶用Forms和Windows复合验证.可以自动切换验证方式. 回复人: SaSBYa(置身珠海,学习与奋斗) ( ) 信誉:100 2005-06-27 11:18:00 得分: 0 呵呵,偶用Forms和Windows复合验证.可以自动切换验证方式. ==================我不太喜欢windows验证,我也说不上什么原因我不会使用session,太浪费资源cookie安全性和稳定性不行。forms验证是在cookie的基础上而来的 SaSBYa(置身珠海,学习与奋斗) 倒是强人,有机会学习一下实现的方法 某些人还在等着ASP.NET 2.0的登陆控件呢,最好是网页就是拖几个DataGrid就完了。下面来剖析一下Form验证的实现吧,微软是这样做的:首先,有一个名为System.Web.Security.FormsAuthenticationModule的模块,他将自己的Enter和Leave方法挂接在Application的两个事件上:public void Init(HttpApplication app){ app.AuthenticateRequest += new EventHandler(this.OnEnter);//开始验证事件 app.EndRequest += new EventHandler(this.OnLeave);//页面输出结束事件。} private void OnEnter(object source, EventArgs eventArgs){//以下代码都是与其它验证模块协同工作的,我猜测,Form验证是最后一个被执行的验证模块。 if (!FormsAuthenticationModule._fAuthChecked || FormsAuthenticationModule._fAuthRequired) { HttpApplication application1 = (HttpApplication) source; HttpContext context1 = application1.Context; AuthenticationConfig config1 = (AuthenticationConfig) context1.GetConfig("system.web/authentication");//取得配置节点。 if (!FormsAuthenticationModule._fAuthChecked) { FormsAuthenticationModule._fAuthRequired = config1.Mode == AuthenticationMode.Forms; FormsAuthenticationModule._fAuthChecked = true; } if (FormsAuthenticationModule._fAuthRequired)//从这里开始才是Form验证 { if (!this._fFormsInit)//如果还没有初始化,执行初始化操作。 { FormsAuthenticationModule.Trace("Initializing Forms Auth Manager"); FormsAuthentication.Initialize(); this._FormsName = config1.CookieName; if (this._FormsName == null) { this._FormsName = ".ASPXAUTH"; } FormsAuthenticationModule.Trace("Forms name is: " + this._FormsName); this._LoginUrl = config1.LoginUrl; if (this._LoginUrl == null) { this._LoginUrl = "login.aspx"; } this._fFormsInit = true; } this.OnAuthenticate(new FormsAuthenticationEventArgs(context1));//这个方法执行验证。 context1.SkipAuthorization = AuthenticationConfig.AccessingLoginPage(context1, this._LoginUrl); } }}private void OnAuthenticate(FormsAuthenticationEventArgs e)//这个是验证方法,由他触发验证事件和执行用户验证。{ HttpCookie cookie1 = null; if (this._eventHandler != null) { this._eventHandler(this, e); } if ((e.Context.User != null) || (e.User != null))//e.User是一个读写属性,这里判断,如果已经有验证模块验证过了, { e.Context.User = (e.Context.User == null) ? e.User : e.Context.User; } else { FormsAuthenticationTicket ticket1 = null; try { ticket1 = FormsAuthenticationModule.ExtractTicketFromCookie(e.Context, this._FormsName);//从Coockie中取得用户身份的验票。看来Form验证的确是基于Coockie的。 } catch (Exception) { ticket1 = null; } if ((ticket1 != null) && !ticket1.Expired)//如果具备身份验票,且未过期。 { FormsAuthenticationTicket ticket2 = ticket1; if (FormsAuthentication.SlidingExpiration)//如果要刷新 { ticket2 = FormsAuthentication.RenewTicketIfOld(ticket1);//刷新验票,其实就是刷新Coockie,这与SessionState的实现原理其实是一样的。 } e.Context.User = new GenericPrincipal(new FormsIdentity(ticket2), new string[0]);//创建一个用户对象,没有任何角色。 if (!ticket2.CookiePath.Equals("/")) { cookie1 = e.Context.Request.Cookies[this._FormsName]; if (cookie1 != null) { cookie1.Path = ticket2.CookiePath; if (ticket2.IsPersistent) { cookie1.Expires = ticket2.Expiration; } } } if (ticket2 != ticket1) { string text1 = FormsAuthentication.Encrypt(ticket2); if (cookie1 != null) { cookie1 = e.Context.Request.Cookies[this._FormsName]; } if (cookie1 == null) { cookie1 = new HttpCookie(this._FormsName, text1); cookie1.Path = ticket2.CookiePath; } if (ticket2.IsPersistent) { cookie1.Expires = ticket2.Expiration; } cookie1.Value = text1; cookie1.Secure = FormsAuthentication.RequireSSL; } if (cookie1 != null) { e.Context.Response.Cookies.Add(cookie1); } } }} 结论,Form验证是直接基于Coockie的。(我说错了)不过很不灵活,大量的亢余代码。 看看做什么产品了.如果客户对象小于二十个计算机使用者的话,Forms是可以的.但是,如果是大型企业特别是跨国企业且以Windows系统为主的客户,windows验证还是重要的. 另外,如果做的是网站的话,则还是Forms验证方式比较好. 我认为得看开发者的习惯以及问题的需求来定的.如果一个开发者,不懂得用Forms验证,那我想他还是会用Cookie+Session了. 动态网页设计初学疑问 关于DropDownList的默认赋值 VS2005 怎么写mobile web啊? 三个很菜很菜的问题 ASP.NET初学者的问题(入门教程中的网站是用什么开发环境做的???) 如何在web服务中使用cookie 谁能告诉我这是什么错误? asp.net 1.1中的Calendar控件的问题! 折叠菜单的设计问题 怎样能使输入框得到焦点时 backcolor 改变? 从数据库取出的字符不能和textbox.text的内容匹配!!! 怎样把在Dreamweaver里画好的table放到DataGrid模板里面
如果说是用户登陆验证的话,一般是都用到,asp.net验证控件+服务器端的验证(如用户名、密码什么的)
不是这意思啊,就是你做后台的时候,不是需要验证到后台这个用户是不是具有管理员权限吗,这个时候,你是怎么判断的呢,根据SESSION?还是什么呢?
是不是ASP.NET的FORM验证啊?
对于什么权限控制,一般用数据库。
继续请教啊!!!@@
可以自动切换验证方式.
呵呵,偶用Forms和Windows复合验证.
可以自动切换验证方式.
==================
我不太喜欢windows验证,我也说不上什么原因我不会使用session,太浪费资源
cookie安全性和稳定性不行。
forms验证是在cookie的基础上而来的
{
app.AuthenticateRequest += new EventHandler(this.OnEnter);//开始验证事件
app.EndRequest += new EventHandler(this.OnLeave);//页面输出结束事件。
}
private void OnEnter(object source, EventArgs eventArgs)
{//以下代码都是与其它验证模块协同工作的,我猜测,Form验证是最后一个被执行的验证模块。
if (!FormsAuthenticationModule._fAuthChecked || FormsAuthenticationModule._fAuthRequired)
{
HttpApplication application1 = (HttpApplication) source;
HttpContext context1 = application1.Context;
AuthenticationConfig config1 = (AuthenticationConfig) context1.GetConfig("system.web/authentication");//取得配置节点。
if (!FormsAuthenticationModule._fAuthChecked)
{
FormsAuthenticationModule._fAuthRequired = config1.Mode == AuthenticationMode.Forms;
FormsAuthenticationModule._fAuthChecked = true;
}
if (FormsAuthenticationModule._fAuthRequired)//从这里开始才是Form验证
{
if (!this._fFormsInit)//如果还没有初始化,执行初始化操作。
{
FormsAuthenticationModule.Trace("Initializing Forms Auth Manager");
FormsAuthentication.Initialize();
this._FormsName = config1.CookieName;
if (this._FormsName == null)
{
this._FormsName = ".ASPXAUTH";
}
FormsAuthenticationModule.Trace("Forms name is: " + this._FormsName);
this._LoginUrl = config1.LoginUrl;
if (this._LoginUrl == null)
{
this._LoginUrl = "login.aspx";
}
this._fFormsInit = true;
}
this.OnAuthenticate(new FormsAuthenticationEventArgs(context1));//这个方法执行验证。
context1.SkipAuthorization = AuthenticationConfig.AccessingLoginPage(context1, this._LoginUrl);
}
}
}private void OnAuthenticate(FormsAuthenticationEventArgs e)//这个是验证方法,由他触发验证事件和执行用户验证。
{
HttpCookie cookie1 = null;
if (this._eventHandler != null)
{
this._eventHandler(this, e);
}
if ((e.Context.User != null) || (e.User != null))//e.User是一个读写属性,这里判断,如果已经有验证模块验证过了,
{
e.Context.User = (e.Context.User == null) ? e.User : e.Context.User;
}
else
{
FormsAuthenticationTicket ticket1 = null;
try
{
ticket1 = FormsAuthenticationModule.ExtractTicketFromCookie(e.Context, this._FormsName);//从Coockie中取得用户身份的验票。看来Form验证的确是基于Coockie的。
}
catch (Exception)
{
ticket1 = null;
}
if ((ticket1 != null) && !ticket1.Expired)//如果具备身份验票,且未过期。
{
FormsAuthenticationTicket ticket2 = ticket1;
if (FormsAuthentication.SlidingExpiration)//如果要刷新
{
ticket2 = FormsAuthentication.RenewTicketIfOld(ticket1);//刷新验票,其实就是刷新Coockie,这与SessionState的实现原理其实是一样的。
}
e.Context.User = new GenericPrincipal(new FormsIdentity(ticket2), new string[0]);//创建一个用户对象,没有任何角色。
if (!ticket2.CookiePath.Equals("/"))
{
cookie1 = e.Context.Request.Cookies[this._FormsName];
if (cookie1 != null)
{
cookie1.Path = ticket2.CookiePath;
if (ticket2.IsPersistent)
{
cookie1.Expires = ticket2.Expiration;
}
}
}
if (ticket2 != ticket1)
{
string text1 = FormsAuthentication.Encrypt(ticket2);
if (cookie1 != null)
{
cookie1 = e.Context.Request.Cookies[this._FormsName];
}
if (cookie1 == null)
{
cookie1 = new HttpCookie(this._FormsName, text1);
cookie1.Path = ticket2.CookiePath;
}
if (ticket2.IsPersistent)
{
cookie1.Expires = ticket2.Expiration;
}
cookie1.Value = text1;
cookie1.Secure = FormsAuthentication.RequireSSL;
}
if (cookie1 != null)
{
e.Context.Response.Cookies.Add(cookie1);
}
}
}
}
如果客户对象小于二十个计算机使用者的话,Forms是可以的.但是,如果是大型企业特别是跨国企业且以Windows系统为主的客户,windows验证还是重要的.