修改目标:以前登陆Cookie保存选项只能选择“永久保存”和“不保存”两种情况,
要将其修改为可选择“不保存”、“保存一天”、“保存一个月”、“保存一年”四种可选情况
修改源码:宝玉汉化版、
涉及部分:皮肤的修改,自定义控件的修改、新增派生自DropDownList的一个类、皮肤XML修改
第一部分:修改皮肤XML
? 在ASP.NET Forums的WEB\Languages存放着皮肤上使用的不同语言文字,我们需要修改\zh-CN目录
下的Resources.xml,查找
自动登录
?
找到后屏蔽掉,增加
不保存保存一天保存一月保存一年
?
第二部分:新增一个派生自DropDownList的一个类
public?class?CookieDropDownList?:?DropDownList?{?
public?CookieDropDownList()?{?//在ResourceManager.GetString中读取了Resources.xml,对怎么对XML进行读取的朋友可以看看??????
Items.Add(new?ListItem(?ResourceManager.GetString("LoginSmall_AutoLogin01")));????
?Items.Add(new?ListItem(?ResourceManager.GetString("LoginSmall_AutoLogin02")?));????
?Items.Add(new?ListItem(?ResourceManager.GetString("LoginSmall_AutoLogin03")));????
?Items.Add(new?ListItem(?ResourceManager.GetString("LoginSmall_AutoLogin04")));????????????}}
?
?
第三部分:皮肤的修改
我们以Skin-LoginSmall.ascx为例
在引用处增加
?
把以前的
?
替换成
?
第四部:自定义控件的修改
登陆都使用的是Login();
Login()类中把所有的CheckBox类型控件修改为DropDownList类型
包括InitializeSkin(Control skin)中的
autoLogin?=?(CheckBox)?skin.FindControl("autoLogin");autoLogin.Text?=?ResourceManager.GetString("LoginSmall_AutoLogin");
?
替换为
autoLogin?=?(DropDownList)?skin.FindControl("autoLogin");
?
增加一个函数用来写入Cookie
public?void?set_Cookie(string?Username,int?Selet_item){??
?switch(Selet_item)?????{?
case?0:?FormsAuthentication.SetAuthCookie(Username,false);?
break;?
case?1:?FormsAuthentication.SetAuthCookie(Username,true);?
forumContext.Context.Response.Cookies[FormsAuthentication.FormsCookieName].Expires=DateTime.Now.AddDays(1);?break;
?case?2:?FormsAuthentication.SetAuthCookie(Username,true);?
forumContext.Context.Response.Cookies[FormsAuthentication.FormsCookieName].Expires=DateTime.Now.AddMonths(1);?break;?
case?3:?FormsAuthentication.SetAuthCookie(Username,true);?
forumContext.Context.Response.Cookies[FormsAuthentication.FormsCookieName].Expires=DateTime.Now.AddYears(1);?break;?}}
?
本文地址:http://com.8s8s.com/it/it8807.htm