//======================================================
//== 这是风讯.net 的首页 default.aspx.cs 文件源代码,最近在研究中,看懂的能否能加下注释,指教一下,菜鸟先谢谢大侠啦, 下面的代码 ,我知道就注释了 ,主要我不明白首页如何和模板页html联系起来的==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
//以上就不用加注释了,添加引用的都能看懂,从下面开始吧,
namespace NetCMS.Web
{
public partial class _default : NetCMS.Web.UI.BasePage
{
protected string SiteRootPath = NetCMS.Common.ServerInfo.GetRootPath();
protected string dimm = NetCMS.Config.UIConfig.dirDumm;
protected string TempletDir = NetCMS.Config.UIConfig.dirTemplet;
public static string gInstallDir = "{$InstallDir}";
public static string gTempletDir = "{$TempletDir}"; //这些都是变量的声明,虽然不是很清晰是干什么用的,但感觉还有点头绪
protected void Page_Load(object sender, EventArgs e)
{
string gChID = Request.QueryString["ChID"]; //下面一多就看不懂了,不明白模板怎么和首页default.aspx联系起来的,指教了 ,谢谢
int ChID = 0;
if (gChID != null && gChID != string.Empty)
{
if (NetCMS.Common.Input.IsInteger(gChID.ToString()))
{
ChID = int.Parse(gChID.ToString());
}
}
NetCMS.Publish.CommonData.Initialize();
string indexname = "index.html";
string TempletPath = NetCMS.Common.Public.readparamConfig("IndexTemplet");
if (ChID != 0)
{
TempletPath = "/" + NetCMS.Config.UIConfig.dirTemplet + "/" + NetCMS.Common.Public.readCHparamConfig("channeltemplet", ChID);
}
TempletPath = TempletPath.Replace("/", "\\");
TempletPath = TempletPath.ToLower().Replace("{@dirtemplet}", TempletDir);
indexname = NetCMS.Common.Public.readparamConfig("IndexFileName");
NetCMS.Publish.Template indexTemp = null;
if (ChID != 0)
{
indexname = NetCMS.Common.Public.readCHparamConfig("channelindexname", ChID);
indexTemp = new NetCMS.Publish.Template(SiteRootPath.Trim('\\') + TempletPath, NetCMS.Publish.TempType.ChIndex);
}
else
{
indexTemp = new NetCMS.Publish.Template(SiteRootPath.Trim('\\') + TempletPath, NetCMS.Publish.TempType.Index);
}
indexTemp.GetHTML();
indexTemp.ReplaceLabels();
indexTemp.ReplaceIMLabels();
string getContent = indexTemp.FinallyContent;
if (Regex.Match(getContent, @"\</head\>[\s\S]*\<body", RegexOptions.IgnoreCase | RegexOptions.Compiled).Success)
{
getContent = Regex.Replace(getContent, "<body", getjs() + "<body", RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
else
{
getContent = getjs() + getContent;
}
getContent = (getContent.Replace(gInstallDir, NetCMS.Publish.CommonData.getUrl())).Replace(gTempletDir, TempletDir);
Response.Write(getContent);
}
protected string getjs() //这个也能看懂,就是风讯的版权门户,使生成的每一个静态页面都含有风讯版权
{
string getajaxJS = "<script language=\"javascript\" type=\"text/javascript\" src=\"" + NetCMS.Publish.CommonData.getUrl() + "/configuration/js/Prototype.js\"></script>\r\n";
getajaxJS += "<script language=\"javascript\" type=\"text/javascript\" src=\"" + NetCMS.Publish.CommonData.getUrl() + "/configuration/js/jspublic.js\"></script>\r\n";
getajaxJS += "<!--Created by foosunv1.0 For Netcms Inc. at " + DateTime.Now + "-->\r\n";
return getajaxJS;
}
}
}