Discuz!NT PageBase基类using System; using System.IO; using System.Web; using System.Text.RegularExpressions; using Discuz.Forum; using Discuz.Common; using Discuz.Config; using Discuz.Entity;namespace Discuz.Web.UI.Pages { /// <summary> /// Discuz!NT页面基类 /// </summary> public class BasePage : System.Web.UI.Page { public string forumpath = BaseConfigs.GetForumPath;
ispost = DNTRequest.IsPost(); isget = DNTRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); isseccode = Utils.InArray(pagename, config.Seccodestatus); if ((isseccode)&&(ispost)) { if (DNTRequest.GetString("vcode") == "") { if (pagename == "showforum.aspx") { //版块如不设置密码,必无校验码 //return; } else if (pagename.EndsWith("ajax.aspx")) { if (DNTRequest.GetString("t") == "quickreply") { ResponseAjaxVcodeError(); } } else { AddErrLine("验证码错误"); } } else {
if (!OnlineUsers.CheckUserVerifyCode(olid, DNTRequest.GetString("vcode"))) { if (pagename.EndsWith("ajax.aspx")) { ResponseAjaxVcodeError(); } else { AddErrLine("验证码错误"); } } } } } } }
要先写一个Class的基类,然后页面的aspx.cs 继承这个class
System.Web.UI.Page <-- YourClass <-- SomePageExample For YourClass:public class YourClass: System.Web.UI.Page { public YourClass(){} protected override void OnInit(EventArgs e) { base.OnInit(e); //Some OnInit Code ... } } Example For SomePage:public partial class SomePage : YourClass { protected void Page_Load(object sender, EventArgs e) { // } }
不好意思,用的VB 原理一样 basepage.vbPublic Class BasePage Inherits System.Web.UI.Page End Class继承 default.aspx.vbPartial Class _Default Inherits BasePageEnd Class
luck0235 说的好,可行..
一个.cs文件做为基类,不过这个基类要继承自system.web.ui.page public class a:system.web.ui.page { 这个基类的某方法完成你的工作,如重写page类某方法 } ------------------------------------- 就按这样做
public class a:system.web.ui.page
{
这个基类的某方法完成你的工作,如重写page类某方法
}2\你的.aspx文件要继承自a
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using Discuz.Forum;
using Discuz.Common;
using Discuz.Config;
using Discuz.Entity;namespace Discuz.Web.UI.Pages
{
/// <summary>
/// Discuz!NT页面基类
/// </summary>
public class BasePage : System.Web.UI.Page
{
public string forumpath = BaseConfigs.GetForumPath;
/// <summary>
/// BasePage类构造函数
/// </summary>
public BasePage()
{ config = GeneralConfigs.GetConfig(); LoadUrlConfig();
userid = Utils.StrToInt(ForumUtils.GetCookie("userid"), -1); //清空当前页面查询统计
Discuz.Data.DbHelper.QueryCount = 0;
// 如果启用游客页面缓存
if (userid == -1)
{
if (config.Guestcachepagetimeout > 0)
{
switch (pagename)
{
case "website.aspx":
isguestcachepage = GetCachePage(pagename);
break;
case "forumindex.aspx":
isguestcachepage = GetCachePage(pagename);
break;
case "spaceindex.aspx":
isguestcachepage = GetCachePage(pagename);
break;
case "albumindex.aspx":
isguestcachepage = GetCachePage(pagename);
break;
case "showtopic.aspx":
int pageid = DNTRequest.GetQueryInt("page", 1);
int topicid = DNTRequest.GetQueryInt("topicid", 0);
if (pageid == 1 && DNTRequest.GetParamCount() == 2 && topicid > 0 && ForumUtils.ResponseTopicCacheFile(topicid, config.Guestcachepagetimeout))
{
TopicStats.Track(topicid, 1);
return;
}
break;
default:
//
break;
}
}
} AddMetaInfo(config.Seokeywords, config.Seodescription, config.Seohead);
if (config.Nocacheheaders == 1)
{
System.Web.HttpContext.Current.Response.BufferOutput = false;
System.Web.HttpContext.Current.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
System.Web.HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
System.Web.HttpContext.Current.Response.Expires = 0;
System.Web.HttpContext.Current.Response.CacheControl = "no-cache";
System.Web.HttpContext.Current.Response.Cache.SetNoStore();
} //当为forumlist.aspx或focuslist_aspx,可能出现在线并发问题,这时系统会延时2秒
if((pagename != "forumlist.aspx") && (pagename != "focuslist.aspx"))
{
oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
}
else
{
try
{
oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
}
catch
{
System.Threading.Thread.Sleep(2000);
oluserinfo = OnlineUsers.UpdateInfo(config.Passwordkey, config.Onlinetimeout);
}
} userid = oluserinfo.Userid;
usergroupid = oluserinfo.Groupid;
username = oluserinfo.Username;
password = oluserinfo.Password;
if (password.Length > 16)
{
userkey = password.Substring(4, 8).Trim();
}
else
{
userkey = "";
}
lastposttime = oluserinfo.Lastposttime;
lastpostpmtime = oluserinfo.Lastpostpmtime;
lastsearchtime = oluserinfo.Lastsearchtime;
olid = oluserinfo.Olid; if (Utils.InArray(DNTRequest.GetString("selectedtemplateid"), Templates.GetValidTemplateIDList()))
{
templateid = DNTRequest.GetInt("selectedtemplateid", 0);
}
else if (Utils.InArray(Utils.GetCookie(Utils.GetTemplateCookieName()), Templates.GetValidTemplateIDList()))
{
templateid = Utils.StrToInt(Utils.GetCookie(Utils.GetTemplateCookieName()), config.Templateid);
} if (templateid == 0)
{
templateid = config.Templateid;
} pmsound = Utils.StrToInt(ForumUtils.GetCookie("pmsound"), 0); usergroupinfo = UserGroups.GetUserGroupInfo(usergroupid); // 根据用户组得到相关联的管理组id
useradminid = usergroupinfo.Radminid; // 如果论坛关闭且当前用户请求页面不是登录页面且用户非管理员, 则跳转至论坛关闭信息页
if (config.Closed == 1 && pagename != "login.aspx" && pagename != "logout.aspx" && pagename != "register.aspx" && useradminid != 1)
{
ShowMessage(1);
return;
} if (config.Onlinetimeout > 0 && userid != -1)
{
onlineusercount = OnlineUsers.GetOnlineAllUserCount();
}
else
{
onlineusercount = OnlineUsers.GetCacheOnlineAllUserCount();
}
if (onlineusercount >= config.Maxonlines && useradminid != 1 && pagename != "login.aspx" && pagename != "logout.aspx")
{
ShowMessage("抱歉,目前访问人数太多,你暂时无法访问论坛.", 0);
return;
}
if (usergroupinfo.Allowvisit != 1 && useradminid != 1 && pagename != "login.aspx" && pagename != "register.aspx" && pagename != "logout.aspx" && pagename != "activationuser.aspx")
{
ShowMessage("抱歉, 您所在的用户组不允许访问论坛", 2);
return;
} // 如果IP访问列表有设置则进行判断
if (config.Ipaccess.Trim() != "")
{
string[] regctrl = Utils.SplitString(config.Ipaccess, "\r\n");
if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl))
{
ShowMessage("抱歉, 系统设置了IP访问列表限制, 您无法访问本论坛", 0);
return;
}
}
// 如果IP访问列表有设置则进行判断
if (config.Ipdenyaccess.Trim() != "")
{
string[] regctrl = Utils.SplitString(config.Ipdenyaccess, "\n");
if (Utils.InIPArray(DNTRequest.GetIP(), regctrl))
{
ShowMessage("由于您严重违反了论坛的相关规定, 已被禁止访问.", 2);
return;
}
} // 如果当前用户请求页面不是登录页面并且当前用户非管理员并且论坛设定了时间段,当时间在其中的一个时间段内,则跳转到论坛登录页面
if (useradminid != 1 && pagename != "login.aspx" && pagename != "logout.aspx" && usergroupinfo.Disableperiodctrl != 1)
{
if (Scoresets.BetweenTime(config.Visitbanperiods))
{
ShowMessage("在此时间段内不允许访问本论坛", 2);
return;
}
} if (userid != -1)
{
string ignore = DNTRequest.GetString("ignore");
newpmcount = Users.GetUserNewPMCount(userid);
realnewpmcount = Math.Abs(newpmcount);
if (ignore.ToLower().Equals("yes"))
{
newpmcount = newpmcount * -1;
Users.SetUserNewPMCount(userid,newpmcount);
}
} templatepath = Templates.GetTemplateItem(templateid).Directory;
nowdate = Utils.GetDate();
nowtime = Utils.GetTime();
nowdatetime = Utils.GetDateTime();
ispost = DNTRequest.IsPost();
isget = DNTRequest.IsGet(); link = ""; script = ""; templatelistboxoptions = Caches.GetTemplateListBoxOptionsCache(); isseccode = Utils.InArray(pagename, config.Seccodestatus);
if ((isseccode)&&(ispost))
{
if (DNTRequest.GetString("vcode") == "")
{
if (pagename == "showforum.aspx")
{
//版块如不设置密码,必无校验码
//return;
}
else if (pagename.EndsWith("ajax.aspx"))
{
if (DNTRequest.GetString("t") == "quickreply")
{
ResponseAjaxVcodeError();
}
}
else
{
AddErrLine("验证码错误");
}
}
else
{
if (!OnlineUsers.CheckUserVerifyCode(olid, DNTRequest.GetString("vcode")))
{
if (pagename.EndsWith("ajax.aspx"))
{
ResponseAjaxVcodeError();
}
else
{
AddErrLine("验证码错误");
}
}
}
} }
}
}
{
public YourClass(){} protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Some OnInit Code ...
}
}
Example For SomePage:public partial class SomePage : YourClass
{
protected void Page_Load(object sender, EventArgs e)
{
//
}
}
basepage.vbPublic Class BasePage
Inherits System.Web.UI.Page
End Class继承
default.aspx.vbPartial Class _Default
Inherits BasePageEnd Class
public class a:system.web.ui.page
{
这个基类的某方法完成你的工作,如重写page类某方法
}
-------------------------------------
就按这样做
换肤 母版页 数据控件使用 编写基类 源代码下载