??xml version="1.0" encoding="utf-8" standalone="yes"?>久久五月天婷婷,亚洲国产精品久久久久婷婷884
,国产在线日本http://www.aygfsteel.com/vls/category/29413.html低调的美?/description>zh-cnSun, 11 May 2008 04:39:21 GMTSun, 11 May 2008 04:39:21 GMT60- 自定义MembershipProvider配合Asp.net 2.0 Login控ghttp://www.aygfsteel.com/vls/archive/2008/02/29/183019.htmlvlsvlsFri, 29 Feb 2008 10:51:00 GMThttp://www.aygfsteel.com/vls/archive/2008/02/29/183019.htmlhttp://www.aygfsteel.com/vls/comments/183019.htmlhttp://www.aygfsteel.com/vls/archive/2008/02/29/183019.html#Feedback0http://www.aygfsteel.com/vls/comments/commentRss/183019.htmlhttp://www.aygfsteel.com/vls/services/trackbacks/183019.html转自Q?a >http://www.programbbs.com/doc/2988.htm
转向Asp.net 2.0Q如果单单看Asp.net 2.0的例子和SDKQ相信你一定对pȝ自带的Login控g有比较深ȝ印象。Asp.Net 2.0的Login控g不用你写一行检用戯入是否合法的E序代码及相x询数据库的SQL脚本Q只需把相应的控g拖到Web表单中,卛_完成用户登陆Q创建用P用户角色理Q修改密码用戯l情况,取回密码{功能模块?br />
Login控g看上去近乎完,而我们现在手头正好来了一个项目要求采用Asp.net 2.0开发,而该目也要求有登陆Q用L理,权限理Q修改密码等功能Q相信绝大多Ch都会考虑使用Login控g来快速搞定这些要求。于是乎Q大家拿Z前的教学例子Q试着分析较深一层的代码Q看看该在哪里对Login控g修改一番,让它满手头目已设计好的数据库表结构。结果发玎ͼ除了aspx文g里面可以对Login控g的外观,提示文字可以自定义外Qcs文g中愣是找不到一行代码,然后l箋MSDN和GoogleQ终于知道,要在自己的项目中直接使用pȝ自带的Login控gQ需要做Q项修改工作Q?br />
1、根据你选用的数据库Q修改Web.config中相应的connectionStrings。系l默认的数据库是SQL Server 2005 ExpressQ如果我们的数据库是Access/SQL2000/2005/OracleQ当然要大改一番了?br />
2、改完Web.configq不够,我们q得执行C:\WINNT\Microsoft.NET\Framework\v2.0.507\aspnet_sqlreg.exe注册你的sql serverQ该E序的作用是在你的数据库中徏立Login控g需要的所有资?大约有上十个表,三十多条存储q程Q上十个视图{等)Q如果你使用的是access/orcaleQ或者是其他格式的数据库Q那你自己去Google相应的SQL脚本吧?br />
OKQ想到Login控g帮你节省的工作量Q相信不h都会咬着牙完成上面的Q项工作。完成上面2工作后Q大家接着读项目需求,发现有用L理和权限管理,q好开发资料上提到Login控g集成的Role角色理模块正好与之对应Q不q以后我们创Z个用户后Q还要再q入一个页面给用户选择所属用LQ当Ӟ采用Role的话Q我们可以设定一个用户同时属于多个用LQ貌似功能很强大哟。l读目需求,发现q些目的用户对象还有不Login控g中没有的属性要保存Q回头再ȝMSDNQ发现Profile可以帮我们解册个问题?br />
嗯,除开使用Login控gQ运行aspnet_sqlreg.exe帮我们徏立的上十个表Q三十多条存储过E,上十个视囄Q我们再不用保存用户的Q何信息了Q以后我们只用在Web.config文g和相应的cs代码中加上Role和Profile的处理代码,卛_完成该项目的登陆Q用L理,密码修改功能。算投入查MSDNQGoogle及修改Web.config文g和相应的cs代码的时_怿原来自己写过自定义Login控g的朋友已l准备发誓再也不Asp.net 2.0自带的Login控g了?br />
其实Q我们完全有更简z通用的办法来重用Asp.net 2.0自带的Login控gQ即只用它最基本的登陆及修改密码功能Q这Q个基本功能照旧?a >工具拖?a >控g出来往Web表单上一扔即可,一行代码都不多加。其他的用户/用户l管理,权限理不用扯上Login控gQ数据库想用什么品就用什么品,mysql/db2/infomax来者不?表结构想怎么设计怎么设计QE-R图,UML囄接照搬就?用户/用户l管理和权限理模块x么规定怎么规定Q自兌Q无限分U都行。M一句话Q让Login控g附带的上十个表,三十多条存储q程Q上十个视图见鬼d?br />
下面l说实现ҎQAsp.net 2.0的Login控g用到?个类来从数据库中获取相应的数据,分别是MemberShipproviderQRoleProvider及ProfileProviderQ系l自带的q?个类的方法的代码被隐藏v来了Q尽没公开Q但实际上就是用我上面一直念叨的上十个表Q三十多条存储过E,上十个视图。不你用什么数据库Q只要想使用Login控g的所有功能,必须保证该数据库中有与之对应的十来个表,三十多条存储q程Q十来个视图?br />
当然QMS的架构设计师也不是某些h惌中的那么无能Q上面的q三个类其实都是抽象c,pȝ的Login控g实际调用的是从这Q个cL生出来的针对SQL Server2000/2005的数据操作类Q灵zȝ架构设计正是在这里体现出来。既然MemberShipProviderQRoleProvider及ProfileProvider三大头是抽象c,那么我们完全可以自定义一个只针对用户表的username及passwordQ个列操作的MemberShipproviderzcd来,重写登陆验证Q修改密码以及其调用的方法,然后在Web.config中把membership的提供者指定ؓ我们自己写的MemberShipproviderzc,q样我们可以和原来一P把Login控g的登陆和修改密码Q个?a >控g往Web表单上一拖了事?br />
下面开始脓代码Q懒的深I的朋友们可以直接把我给出的cs代码贴回去,Zcs文g攑ֈApp_Code目录下,然后按照后面的Web.config修改相应的connectionStrings和membership卛_Q以后Q何项目要利用Asp.net 2.0的Login控g的登陆和修改密码都是q样照葫芦画瓢,够傻瓜吧?br />
- using System;
- using System.Data;
- using System.Configuration;
- using System.Data.SqlClient;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Data.SqlTypes;
- using System.Web;
- using System.Web.Security;
-
- /// <summary>
-
-
- public class MyMemberShip : MembershipProvider
- {
- private bool _requiresQuestionAndAnswer;
- private int _minRequiredPasswordLength;
- public MyMemberShip()
- {
-
-
-
- }
- public override string ApplicationName
- {
- get
- {
- throw new Exception("The method or operation is not implemented.");
- }
- set
- {
- throw new Exception("The method or operation is not implemented.");
- }
- }
- public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config)
- {
-
- if (config["requiresQuestionAndAnswer"].ToLower() == "true")
- _requiresQuestionAndAnswer = true;
- else
- _requiresQuestionAndAnswer = false;
- int.TryParse(config["minPasswordLength"], out _minRequiredPasswordLength);
- base.Initialize(name, config);
- }
- public override bool ChangePassword(string username, string oldPassword, string newPassword)
- {
- using (SqlConnection connection = new SqlConnection(DBBase.DBConnectionString))
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "update [User] set user_pwd=@newpwd where user_name=@name and user_pwd=@oldpwd";
- command.Parameters.AddWithValue("@name", username);
- command.Parameters.AddWithValue("@oldpwd", CryptUtil.GetStringHashValue1(StringUtil.SqlEscape(oldPassword)));
- command.Parameters.AddWithValue("@newpwd", CryptUtil.GetStringHashValue1(StringUtil.SqlEscape(newPassword)));
- command.Connection = connection;
- connection.Open();
- return (int)command.ExecuteNonQuery() > 0 ? true : false;
- }
-
- }
-
- public override bool ChangePasswordQuestionAndAnswer(string username, string password, string newPasswordQuestion, string newPasswordAnswer)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override bool DeleteUser(string username, bool deleteAllRelatedData)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override bool EnablePasswordReset
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override bool EnablePasswordRetrieval
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize, out int totalRecords)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override int GetNumberOfUsersOnline()
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override string GetPassword(string username, string answer)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override MembershipUser GetUser(string username, bool userIsOnline)
- {
- DateTime myDate = DateTime.Today;
- MembershipUser user = new MembershipUser(
- Name,
- username,
- null,
- bobcy@21cn.com,
- String.Empty,
- String.Empty,
- true,
- false,
- DateTime.Now,
- DateTime.Now,
- DateTime.Now,
- DateTime.Now,
- new DateTime(1980, 1, 1)
- );
- return user;
- }
-
- public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override string GetUserNameByEmail(string email)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override int MaxInvalidPasswordAttempts
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override int MinRequiredNonAlphanumericCharacters
- {
- get { return 0; }
- }
-
- public override int MinRequiredPasswordLength
- {
- get { return _minRequiredPasswordLength; }
- }
-
- public override int PasswordAttemptWindow
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override MembershipPasswordFormat PasswordFormat
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override string PasswordStrengthRegularExpression
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override bool RequiresQuestionAndAnswer
- {
- get { return _requiresQuestionAndAnswer; }
- }
-
- public override bool RequiresUniqueEmail
- {
- get { throw new Exception("The method or operation is not implemented."); }
- }
-
- public override string ResetPassword(string username, string answer)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override bool UnlockUser(string userName)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override void UpdateUser(MembershipUser user)
- {
- throw new Exception("The method or operation is not implemented.");
- }
-
- public override bool ValidateUser(string username, string password)
- {
- using (SqlConnection connection = new SqlConnection(DBBase.DBConnectionString))
- {
- SqlCommand command = new SqlCommand();
- command.CommandText = "select count(0) from [User] where user_name=@name and user_pwd=@pwd";
- command.Parameters.AddWithValue("@name", username);
- command.Parameters.AddWithValue("@pwd", password);
- command.Connection = connection;
- connection.Open();
- return ((int)command.ExecuteScalar()) > 0 ? true : false;
- }
- }
- }
Web.Config的membership节这样写QconnectionStrings和数据库有关Q不同的数据库差别很大,大家自己GoogleQ我׃列出来了?br />
<membership defaultProvider="MyMemberShip">
<providers>
<clear/>
<add name="MyMemberShip" type="MyMemberShip" requiresQuestionAndAnswer="false" connectionString="AdminSqlServer" minRequiredNonalphanumericCharacters="0" />
</providers>
</membership>

如果我们惛_用户验证登陆成功后做一些额外的处理Q可以给登陆控g的登陆按钮添加一个事Ӟ相应的代码如下:
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)


{
if (Membership.ValidateUser(Login1.UserName, Login1.Password))


{
//q里d你的额外处理代码Q如Session,login日至{等
e.Authenticated = true;
}
}


]]>- firefox下insertRowhttp://www.aygfsteel.com/vls/archive/2008/02/12/179652.htmlvlsvlsMon, 11 Feb 2008 18:14:00 GMThttp://www.aygfsteel.com/vls/archive/2008/02/12/179652.htmlhttp://www.aygfsteel.com/vls/comments/179652.htmlhttp://www.aygfsteel.com/vls/archive/2008/02/12/179652.html#Feedback0http://www.aygfsteel.com/vls/comments/commentRss/179652.htmlhttp://www.aygfsteel.com/vls/services/trackbacks/179652.html
|
ie6 |
firefox |
opera |
insertRow |
支持, 默认参数-1,默认d到最?/td>
| 支持Q?nbsp;但不支持默认参数
| 支持Q默认参?
默认d到最?br />
|
appendChild |
不支?/td>
| 支持Q但是增?nbsp;tr后不影响rows |
支持Q效果同insertRow(-1),影响rows |
dom level 1:http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-64060425
//向tableq加一个空行:
var otr = otable.insertRow(-1);
var otd = document.createElement("td");
otd.innerHTML = " ";
otd.className = "XXXX";
otr.appendChild(otd);
q样可以运行在q三U浏览器上了

]]>
վ֩ģ壺
|
|
山|
ű|
|
|
Ļ|
|
ٺ|
쳤|
Ϫ|
|
|
|
|
°Ͷ|
|
ƽ|
߰|
ұ|
˫Ѽɽ|
÷ӿ|
Ϫ|
ʯ|
|
|
Ϻ|
Ӳ|
|
|
|
|
|
̩˳|
ȫ|
Ұ|
ƽ|
峣|
|
ԣ|
|