Discuz2.5菜鸟解析-1

前天上CSDN看到,Discuz出了新的版本2.5。当时立马跑到了Discuz的老家下载了源程序来看看。对于第一次看Discuz的兄弟们基本上100%都是不适应的,因为discuz为了考虑到程序员与美工搭配的原因还有就是性能的原因没有采用太多的代码后置的程序,反而使用了大量了类似于JSP的Model2的MVC结构,呵呵,也许开发人员以前是以PHP和Java开发为主,所以写的程序确实和我们平常看到的有点不同。

现在我们就来一点一点儿的研究一下这些代码,看看里面有什么玄机。首先我们先看一下,discuz2.5的项目结构。

源程序结构

这里面有几个非常重要的项目,一个是Discuz.Forum这个项目,由于Discuz采用了HttpModel技术,所以第一次看Discuz的菜鸟们也许会有点蒙,那就是Discuz.Web项目中的index.asp什么也没有。如果不清楚情况的同志们还以为是Discuz在忽悠我们哪,其实不然。我们来仔细的看一下Web项目的二个配置文件:Web.config dnt.conf.

DNT.config文件的内容

   1:  <?xml version="1.0"?>
   2:  <BaseConfigInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   3:    <Dbconnectstring>
   4:  Data Source=CHU888-PC\SQLEXPRESS;User ID=sa;Password=123456;Initial Catalog=dnt;Pooling=true
   5:  </Dbconnectstring>
   6:    <Tableprefix>dnt_</Tableprefix>
   7:    <Forumpath>/</Forumpath>
   8:    <Dbtype>SqlServer</Dbtype>
   9:    <Founderuid>1</Founderuid>
  10:  </BaseConfigInfo>

在这个文件中我们配置了数据的链接字符串,表的前缀名,数据库的类型,还有就是Theme号‘

再来看一下Web.config中的内容

   1:  <?xml version="1.0" encoding="utf-8"?>
   2:  <configuration>
   3:   
   4:    <system.web>
   5:   
   6:      <compilation defaultLanguage="c#" debug="true" />
   7:   
   8:      <authorization>
   9:        <allow users="*" />
  10:   
  11:      </authorization>
  12:   
  13:      <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
  14:   
  15:   
  16:      <customErrors mode="Off" />
  17:   
  18:   
  19:      <globalization requestEncoding="utf-8" responseEncoding="utf-8" fileEncoding="utf-8" />
  20:   
  21:   
  22:      <pages validateRequest="false" enableEventValidation="false" enableViewStateMac="false" viewStateEncryptionMode="Never" />
  23:   
  24:   
  25:      <httpModules>
  26:        <add type="Discuz.Forum.HttpModule, Discuz.Forum" name="HttpModule" />
  27:      </httpModules>
  28:   
  29:      <xhtmlConformance mode="Legacy" />
  30:   
  31:      <httpRuntime maxRequestLength="2097151" executionTimeout="3600" />
  32:   
  33:      <webServices>
  34:        <protocols>
  35:          <add name="HttpGet" />
  36:          <add name="HttpPost" />
  37:        </protocols>
  38:      </webServices>
  39:   
  40:   
  41:    </system.web>
  42:   
  43:    <system.webServer>
  44:      <validation validateIntegratedModeConfiguration="false" />
  45:      <modules>
  46:        <!--  注意:此节设置由Discuz!NT接管http请求。不会干涉对非Discuz!NT论坛路径下的请求。-->
  47:        <add type="Discuz.Forum.HttpModule, Discuz.Forum" name="HttpModule" />
  48:      </modules>
  49:      <defaultDocument>
  50:        <files>
  51:          <clear />
  52:          <add value="index.aspx" />
  53:          <add value="forumindex.aspx" />
  54:          <add value="spaceindex.aspx" />
  55:          <add value="albumindex.aspx" />
  56:        </files>
  57:      </defaultDocument>
  58:      <directoryBrowse enabled="true" />
  59:    </system.webServer>
  60:   
  61:  </configuration>

在25行至27行我们注册一个httpmodules,在43行至59行我们对所有http请求进行了接管,所以你在访问index.aspx文件时httpmodules会自动对其程序进行接管,这个有点像java中的serlvet。

具体接管代码在Discuz.forum中的HttpModule.cs文件中,这个文件实现了System.Web.IHttpModule,对其所有文件的请求进行了接管,具体httpmodule是如何实现的,我记得到园子中有一个非常好的系列文章,大家可以自行查找。

HttpModule.cs的主要转向内容如下:

   1:   if (requestPath.EndsWith("/index.aspx"))
   2:   {
   3:       if (config.Indexpage == 0)
   4:       {
   5:           if (config.BrowseCreateTemplate == 1)
   6:           {
   7:               CreateTemplate(forumPath, Templates.GetTemplateItem(int.Parse(strTemplateid)).Directory, 
   8:               "forumindex.aspx", int.Parse(strTemplateid));
   9:           }
  10:           context.RewritePath(forumPath + "aspx/" + strTemplateid + "/forumindex.aspx");
  11:       }
  12:       else
  13:       {
  14:           if (config.BrowseCreateTemplate == 1)
  15:           {
  16:               CreateTemplate(forumPath, Templates.GetTemplateItem(int.Parse(strTemplateid)).Directory, 
  17:               "website.aspx", int.Parse(strTemplateid));
  18:           }
  19:           context.RewritePath(forumPath + "aspx/" + strTemplateid + "/website.aspx");
  20:       }
  21:   
  22:       return;
  23:   }

现在基本上大家对这个源程序的流程处理有了一个了解了,我们再接着来看,它是如果实现论坛源程序的自动安装的。

install 

安装的功能主要集中在Discuz.Web中的Install目录。

第一步的安装界面:

1

其具体代码如下:

   1:  <%@ Import Namespace="Discuz.Common" %>
   2:  <%@ Import Namespace="Discuz.Install" %>
   3:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   4:  <html>
   5:  <%=SetupPage.header%>
   6:  <body>
   7:      <table width="700" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#666666">
   8:          <tr>
   9:              <td bgcolor="#ffffff">
  10:                  <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  11:                      <tr>
  12:                          <td colspan="2" bgcolor="#333333">
  13:                              <table width="100%" border="0" cellspacing="0" cellpadding="8">
  14:                                  <tr>
  15:                                      <td>
  16:                                          <font color="#ffffff">欢迎安装
  17:                                              <%=SetupPage.producename%>
  18:                                          </font>
  19:                                      </td>
  20:                                  </tr>
  21:                              </table>
  22:                          </td>
  23:                      </tr>
  24:                      <tr>
  25:                          <td width="180" valign="top">
  26:                              <%=SetupPage.logo%>
  27:                          </td>
  28:                          <td width="520" valign="top">
  29:                              <br>
  30:                              <br>
  31:                              <table id="Table2" cellspacing="1" cellpadding="1" width="90%" align="center" border="0">
  32:                                  <tr>
  33:                                      <td>
  34:                                          <p>
  35:                                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 欢迎您选择安装<%=SetupPage.producename%></p>
  36:                                          <p>
  37:                                              &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 本向导将协助您一步步的安装和初始化系统.</p>
  38:                                          <p>
  39:    &             ; 强烈建议您在运行本向导前仔细阅读程序包中的《安装说明》文档, 如果您已经阅读过, 请点击下一步.</p>
  40:                                      </td>
  41:                                  </tr>
  42:                              </table>
  43:                              <p>
  44:                              </p>
  45:                          </td>
  46:                      </tr>
  47:                      <tr>
  48:                          <td>
  49:                              &nbsp;
  50:                          </td>
  51:                          <td>
  52:                              <table width="90%" border="0" cellspacing="0" cellpadding="8">
  53:                                  <tr>
  54:                                      <td align="right">
  55:                           <input type="button" onclick="javascript:window.location.href='step2.aspx';" value="下一步">
  56:                                      </td>
  57:                                  </tr>
  58:                              </table>
  59:                          </td>
  60:                      </tr>
  61:                  </table>
  62:              </td>
  63:          </tr>
  64:      </table>
  65:      <%=SetupPage.footer%>
  66:  </body>
  67:  </html>

大家可以看的出来,在第一步的页面中根本就没有用到任何代码后置,基本上都是采用<%%>来显示必要的信息数据,其中主要用到了。

<%=SetupPage.header%>

<%=SetupPage.producename%>

<%=SetupPage.logo%>

<%=SetupPage.producename%>

<%=SetupPage.footer%>

以上程序主要是调用了Discuz.Install.SetupPage.cs

   1:  using System;
   2:  using System.IO;
   3:  using System.Text;
   4:  using System.Web;
   5:  using System.Web.UI;
   6:   
   7:  using Discuz.Common;
   8:  using Discuz.Forum;
   9:  using Discuz.Config;
  10:  using System.Collections;
  11:   
  12:  namespace Discuz.Install
  13:  {
  14:      /// <summary>
  15:      /// SetupPage 的摘要说明。
  16:      /// </summary>
  17:      public class SetupPage : System.Web.UI.Page
  18:      {
  19:   
  20:          public static readonly string producename = Utils.GetAssemblyProductName();  //当前产品版本名称
  21:   
  22:          public static readonly string footer = "";
  23:   
  24:          public static readonly string logo = "<img src=\"images/logo.jpg\" width=\"180\" height=\"300\">"; //安装的LOGO
  25:   
  26:          public static readonly string header = ""; //html页的的<head>属性
  27:   
  28:   
  29:          static SetupPage()
  30:          {
  31:   
  32:              header = "<HEAD><title>安装 " + Utils.GetAssemblyProductName() + "</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n";
  33:              header += "<LINK rev=\"stylesheet\" media=\"all\" href=\"css/styles.css\" type=\"text/css\" rel=\"stylesheet\"></HEAD>\r\n";
  34:              header += "<script language=\"javascript\" src=\"js/setup.js\"></script>\r\n";
  35:   
  36:              footer = "\r\n<br />\r\n<br /><table width=\"700\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" ID=\"Table1\">";
  37:              footer += "<tr><td align=\"center\"><div align=\"center\" style=\"position:relative ; padding-top:60px;font-size:14px; font-family: Arial\">";
  38:              footer += "<hr style=\"height:1; 600; height:1; color:#CCCCCC\" />Powered by <a style=\"COLOR: #000000\" href=\"http://nt.discuz.net\" target=\"_blank\">" + Utils.GetAssemblyProductName() + "</a>";
  39:              footer += " &nbsp;<br />&copy; 2001-" + Utils.GetAssemblyCopyright().Split(',')[0] + " <a style=\"COLOR: #000000;font-weight:bold\" href=\"http://www.comsenz.com\" target=\"_blank\">Comsenz Inc.</a></div></td></tr></table>";
  40:          }
  41:   
  42:   
  43:          //当用户点击按钮时,将其置为无效
  44:          public void DisableSubmitBotton(Page mypage, System.Web.UI.WebControls.Button submitbutton)
  45:          {
  46:              RegisterAdminPageClientScriptBlock();
  47:   
  48:              //保证 __doPostBack(eventTarget, eventArgument) 正确注册
  49:  #if NET1
  50:              mypage.GetPostBackEventReference(submitbutton,"");        
  51:  #else
  52:              mypage.ClientScript.GetPostBackEventReference(submitbutton, "");
  53:  #endif
  54:   
  55:              StringBuilder sb = new StringBuilder();
  56:   
  57:              //保证验证函数的执行
  58:              sb.Append("if (typeof(Page_ClientValidate) == 'function') { if (Page_ClientValidate() == false) { return false; }}");
  59:   
  60:              // disable所有submit按钮
  61:              sb.Append("disableOtherSubmit();");
  62:   
  63:              //sb.Append("document.getElementById('Layer5').innerHTML ='正在运行操作</td></tr></table><BR />';");
  64:              sb.Append("document.getElementById('success').style.display ='block';");
  65:   
  66:  #if NET1   
  67:      //用__doPostBack来提交,保证按钮的服务器端click事件执行
  68:              sb.Append(this.GetPostBackEventReference(submitbutton,""));   
  69:  #else
  70:              sb.Append(this.ClientScript.GetPostBackEventReference(submitbutton, ""));
  71:  #endif
  72:              sb.Append(";");
  73:              submitbutton.Attributes.Add("onclick", sb.ToString());
  74:          }
  75:   
  76:   
  77:          public void RegisterAdminPageClientScriptBlock()
  78:          {
  79:   
  80:              string script = "<div id=\"success\" style=\"position:absolute;z-index:300;height:120px;284px;left:50%;top:50%;margin-left:-150px;margin-top:-80px;\">\r\n" +
  81:                            "    <div id=\"Layer2\" style=\"position:absolute;z-index:300;270px;height:90px;background-color: #FFFFFF;border:solid #000000 1px;font-size:14px;\">\r\n" +
  82:                            "        <div id=\"Layer4\" style=\"height:26px;background:#333333;line-height:26px;padding:0px 3px 0px 3px;font-weight:bolder;color:#fff \">操作提示</div>\r\n" +
  83:                            "        <div id=\"Layer5\" style=\"height:64px;line-height:150%;padding:0px 3px 0px 3px;\" align=\"center\"><br />正在执行操作,请稍等...</div>\r\n" +
  84:                            "    </div>\r\n" +
  85:                            "    <div id=\"Layer3\" style=\"position:absolute;270px;height:90px;z-index:299;left:4px;top:5px;background-color: #cccccc;\"></div>\r\n" +
  86:                            "</div>\r\n" +
  87:                            "<script> \r\n" +
  88:                            "document.getElementById('success').style.display ='none'; \r\n" +
  89:                            "</script> \r\n" +
  90:                            "<script language=\"JavaScript1.2\" src=\"../js/divcover.js\"></script>\r\n";
  91:   
  92:   
  93:  #if NET1
  94:              base.RegisterClientScriptBlock("Page", script);
  95:  #else
  96:              base.ClientScript.RegisterClientScriptBlock(this.GetType(), "Page", script);
  97:  #endif
  98:          }
  99:   
 100:          public new void RegisterStartupScript(string key, string scriptstr)
 101:          {
 102:   
 103:              string message = "<BR />操作成功, 系统将返回论坛首页...";
 104:   
 105:              if (key == "PAGE")
 106:              {
 107:                  string script = "";
 108:   
 109:                  script = "<div id=\"success\" style=\"position:absolute;z-index:300;height:120px;284px;left:50%;top:50%;margin-left:-150px;margin-top:-80px;\">\r\n" +
 110:                         "    <div id=\"Layer2\" style=\"position:absolute;z-index:300;270px;height:90px;background-color: #FFFFFF;border:solid #000000 1px;font-size:14px;\">\r\n" +
 111:                         "        <div id=\"Layer4\" style=\"height:26px;background:#333;line-height:26px;padding:0px 3px 0px 3px;font-weight:bolder;color:#fff \">操作提示</div>\r\n" +
 112:                         "        <div id=\"Layer5\" style=\"height:64px;line-height:150%;padding:0px 3px 0px 3px;\" align=\"center\">" + message + "</div>\r\n" +
 113:                         "    </div>\r\n" +
 114:                         "    <div id=\"Layer3\" style=\"position:absolute;270px;height:90px;z-index:299;left:4px;top:5px;background-color: #cccccc;\"></div>\r\n" +
 115:                         "</div>\r\n" +
 116:                         "<script> \r\n" +
 117:                         "var bar=0;\r\n" +
 118:                         "document.getElementById('success').style.display = \"block\"; \r\n" +
 119:                         "count() ; \r\n" +
 120:                         "function count(){ \r\n" +
 121:                         "bar=bar+4; \r\n" +
 122:                         "if (bar<99) \r\n" +
 123:                         "{setTimeout(\"count()\",100);} \r\n" +
 124:                         "else { \r\n" +
 125:                         "    document.getElementById('success').style.display = \"none\"; \r\n" +
 126:                         scriptstr + "} \r\n" +
 127:                         "} \r\n" +
 128:                         "</script> \r\n" +
 129:                         "<script language=\"JavaScript1.2\" src=\"../admin/js/divcover.js\"></script>\r\n" +
 130:                         "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
 131:   
 132:                  Response.Write(script);
 133:              }
 134:              else
 135:              {
 136:  #if NET1
 137:                  base.RegisterStartupScript(key, scriptstr);
 138:  #else
 139:                  base.ClientScript.RegisterStartupScript(this.GetType(), key, scriptstr);
 140:  #endif
 141:              }
 142:          }
 143:   
 144:          public static string InitialSystemValidCheck(ref bool error)
 145:          {
 146:              error = false;
 147:              StringBuilder sb = new StringBuilder();
 148:              sb.Append("<table cellSpacing='0' cellPadding='0' width='90%' align='center' border='0' bgcolor='#666666' style='font-size:12px'>");
 149:   
 150:              HttpContext context = HttpContext.Current;
 151:   
 152:              string filename = null;
 153:              if (context != null)
 154:                  filename = context.Server.MapPath("/DNT.config");
 155:              else
 156:                  filename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DNT.config");
 157:   
 158:              //系统BIN目录检查
 159:              sb.Append(IISSystemBINCheck(ref error));
 160:   
 161:   
 162:              //            GetRootDntconfigPath();
 163:              //检查Dnt.config文件的有效性
 164:              if (!GetRootDntconfigPath())
 165:              {
 166:                  sb.Append("<tr style=\"height:15px\"><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'> DNT.config 不可写或没有放置正确, 相关问题详见安装文档!</td></tr>");
 167:                  error = true;
 168:              }
 169:              else
 170:              {
 171:                  sb.Append("<tr style=\"height:15px\"><td bgcolor='#ffffff' width='5%'><img src='images/ok.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>对 DNT.config 验证通过!</td></tr>");
 172:              }
 173:   
 174:              //            if(!SystemRootCheck())
 175:              //            {
 176:              //                sb.Append("您对系统文件dnt.config没有写入权限!<br />");
 177:              //            }
 178:   
 179:   
 180:              //检查系统目录的有效性
 181:              string folderstr = "admin,aspx,avatars,cache,config,editor,images,templates,upload";
 182:              foreach (string foldler in folderstr.Split(','))
 183:              {
 184:                  if (!SystemFolderCheck(foldler))
 185:                  {
 186:                      sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>对 " + foldler + " 目录没有写入和删除权限!</td></tr>");
 187:                      error = true;
 188:                  }
 189:                  else
 190:                  {
 191:                      sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/ok.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>对 " + foldler + " 目录权限验证通过!</td></tr>");
 192:                  }
 193:              }
 194:              string filestr = "admin\\xml\\navmenu.config,javascript\\mymenu.js,install\\systemfile.aspx,upgrade\\systemfile.aspx";
 195:              foreach (string file in filestr.Split(','))
 196:              {
 197:                  if (!SystemFileCheck(file))
 198:                  {
 199:                      sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>对 " + file.Substring(0,file.LastIndexOf('\\')) + " 目录没有写入和删除权限!</td></tr>");
 200:                      error = true;
 201:                  }
 202:                  else
 203:                  {
 204:                      sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/ok.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>对 " + file.Substring(0, file.LastIndexOf('\\')) + " 目录权限验证通过!</td></tr>");
 205:                  }
 206:              }
 207:   
 208:             if(!TempTest())
 209:             {
 210:                 sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>您没有对 " + Path.GetTempPath() + " 文件夹访问权限,详情参见安装文档.</td></tr>");
 211:                 error = true;
 212:             }
 213:             else
 214:             {
 215:              if (!SerialiazeTest())
 216:              {
 217:                  sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>对config文件反序列化失败,详情参见安装文档.</td></tr>");
 218:                  error = true;
 219:              }
 220:              else
 221:              {
 222:                  sb.Append("<tr><td bgcolor='#ffffff' width='5%'><img src='images/ok.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>反序列化验证通过!</td></tr>");
 223:              } 
 224:             }
 225:              sb.Append("</table>");
 226:           
 227:              return sb.ToString();
 228:          }
 229:   
 230:          public static bool GetRootDntconfigPath()
 231:          {
 232:              try
 233:              {
 234:   
 235:                  HttpContext context = HttpContext.Current;
 236:   
 237:                  //string[] webconfigpath = {Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DNT.config"), Path.Combine(context.Request.PhysicalApplicationPath, "dnt.config"),
 238:                  //    Utils.GetMapPath("../dnt.config") ,Utils.GetMapPath("../../dnt.config"),Utils.GetMapPath("../../../dnt.config") };
 239:                  //foreach (string webconfig in webconfigpath)
 240:                  //{
 241:                  //    if (Utils.FileExists(webconfig))
 242:                  //    {
 243:                  //        return SystemFileCheck(webconfig);
 244:                  //    }
 245:                  //}
 246:                  //return false;
 247:                  //如果文件不存在退出
 248:                  //string webconfigpath = Path.Combine(context.Request.PhysicalApplicationPath, "dnt.config");
 249:                  string webconfigfile = "";
 250:                  if (!Utils.FileExists(webconfigfile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DNT.config"))
 251:                      && (!Utils.FileExists(webconfigfile = Path.Combine(context.Request.PhysicalApplicationPath, "dnt.config")))
 252:                      && (!Utils.FileExists(webconfigfile = Utils.GetMapPath("../dnt.config")))
 253:                      && (!Utils.FileExists(webconfigfile = Utils.GetMapPath("../../dnt.config")))
 254:                      && (!Utils.FileExists(webconfigfile = Utils.GetMapPath("../../../dnt.config"))))
 255:                  {
 256:                      return false;
 257:                  }
 258:                  else
 259:                  {
 260:                      StreamReader sr = new StreamReader(webconfigfile);
 261:                      string content = sr.ReadToEnd();
 262:                      sr.Close();
 263:                      content += " ";
 264:                      StreamWriter sw = new StreamWriter(webconfigfile, false);
 265:                      sw.Write(content);
 266:                      sw.Close();
 267:                      return true;
 268:                  }
 269:              }
 270:              catch
 271:              {
 272:                  return false;
 273:              }
 274:          }
 275:   
 276:          public static bool SystemRootCheck()
 277:          {
 278:              HttpContext context = HttpContext.Current;
 279:   
 280:              string physicsPath = null;
 281:   
 282:              if (context != null)
 283:                  physicsPath = context.Server.MapPath("/");
 284:              else
 285:                  physicsPath = AppDomain.CurrentDomain.BaseDirectory;
 286:   
 287:              try
 288:              {
 289:                  using (FileStream fs = new FileStream(physicsPath + "\\a.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
 290:                  {
 291:                      fs.Close();
 292:                  }
 293:   
 294:                  System.IO.File.Delete(physicsPath + "\\a.txt");
 295:   
 296:                  return true;
 297:              }
 298:              catch
 299:              {
 300:                  return false;
 301:              }
 302:   
 303:          }
 304:   
 305:   
 306:          public static string IISSystemBINCheck(ref bool error)
 307:          {
 308:              string binfolderpath = HttpRuntime.BinDirectory;
 309:   
 310:              string result = "";
 311:              try
 312:              {
 313:                  string[] assemblylist = new string[] { "Discuz.Aggregation.dll", "Discuz.Cache.dll", "Discuz.Common.dll", "Discuz.Config.dll", 
 314:                      "Discuz.Control.dll", "Discuz.Data.dll", "Discuz.Data.SqlServer.dll","Discuz.Entity.dll","Discuz.Event.dll", "Discuz.Forum.dll",
 315:                      "Discuz.Install.dll", "Discuz.Plugin.dll","Discuz.Plugin.Preview.Jpg.dll","Discuz.Plugin.Spread.dll", "Discuz.Web.Admin.dll",
 316:                      "Discuz.Web.dll", "Discuz.Web.Services.dll","Interop.SQLDMO.dll","Newtonsoft.Json.dll" };
 317:                  bool isAssemblyInexistence = false;
 318:                  ArrayList inexistenceAssemblyList = new ArrayList();
 319:                  foreach (string assembly in assemblylist)
 320:                  {
 321:                      if (!File.Exists(binfolderpath + assembly))
 322:                      {
 323:                          isAssemblyInexistence = true;
 324:                          error = true;
 325:                          inexistenceAssemblyList.Add(assembly);
 326:                      }
 327:                  }
 328:                  if (isAssemblyInexistence)
 329:                  {
 330:                      foreach (string assembly in inexistenceAssemblyList)
 331:                      {
 332:                              result += "<tr><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>" + assembly + " 文件放置不正确<br/>请将所有的dll文件复制到目录 " + binfolderpath + " 中.</td></tr>";
 333:                      }
 334:                  }
 335:              }
 336:              catch
 337:              {
 338:                  result += "<tr><td bgcolor='#ffffff' width='5%'><img src='images/error.gif' width='16' height='16'></td><td bgcolor='#ffffff' width='95%'>请将所有的dll文件复制到目录 " + binfolderpath + " 中.</td></tr>";
 339:                  error = true;
 340:              }
 341:   
 342:              return result;
 343:          }
 344:   
 345:          public static bool SystemFolderCheck(string foldername)
 346:          {
 347:              string physicsPath = Utils.GetMapPath(@"..\" + foldername);
 348:              try
 349:              {
 350:                  using (FileStream fs = new FileStream(physicsPath + "\\a.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
 351:                  {
 352:                      fs.Close();
 353:                  }
 354:                  if (File.Exists(physicsPath + "\\a.txt"))
 355:                  {
 356:                      System.IO.File.Delete(physicsPath + "\\a.txt");
 357:                      return true;
 358:                  }
 359:                  else
 360:                  {
 361:                      return false;
 362:                  }
 363:              }
 364:              catch
 365:              {
 366:                  return false;
 367:              }
 368:          }
 369:   
 370:          public static bool SystemFileCheck(string filename)
 371:          {
 372:              filename = Utils.GetMapPath(@"..\" + filename);
 373:              try
 374:              {
 375:                  if (filename.IndexOf("systemfile.aspx") == -1 && !File.Exists(filename))
 376:                      return false;
 377:                  if (filename.IndexOf("systemfile.aspx") != -1)  //做删除测试
 378:                  {
 379:                      File.Delete(filename);
 380:                      return true;
 381:                  }
 382:                  StreamReader sr = new StreamReader(filename);
 383:                  string content = sr.ReadToEnd();
 384:                  sr.Close();
 385:                  content += " ";
 386:                  StreamWriter sw = new StreamWriter(filename, false);
 387:                  sw.Write(content);
 388:                  sw.Close();
 389:                  return true;
 390:              }
 391:              catch
 392:              {
 393:                  return false;
 394:              }
 395:          }
 396:   
 397:          private static bool SerialiazeTest()
 398:          {
 399:              try
 400:              {
 401:                  string configPath = HttpContext.Current.Server.MapPath("../config/general.config");
 402:                  GeneralConfigInfo __configinfo = GeneralConfigs.Deserialize(configPath);
 403:                  __configinfo.Passwordkey = ForumUtils.CreateAuthStr(10);
 404:                  SerializationHelper.Save(__configinfo, configPath);
 405:                  return true;
 406:              }
 407:              catch
 408:              {
 409:                  return false;
 410:              }
 411:          }
 412:   
 413:   
 414:          private static bool TempTest()
 415:          {
 416:              string UserGuid = Guid.NewGuid().ToString();
 417:              string TempPath = Path.GetTempPath();
 418:              string path = TempPath + UserGuid;
 419:              try
 420:              {
 421:   
 422:                  using (StreamWriter sw = new StreamWriter(path))
 423:                  {
 424:                      sw.WriteLine(DateTime.Now);
 425:                  }
 426:   
 427:                  using (StreamReader sr = new StreamReader(path))
 428:                  {
 429:                      sr.ReadLine();
 430:                      return true;
 431:                  }
 432:   
 433:   
 434:              }
 435:              catch
 436:              {
 437:                  return false;
 438:   
 439:              }
 440:   
 441:          }
 442:      }
 443:  }

基本上看到这一步大家就基本上要晕了,呵呵。。全部都是字符串拼接输出,乐了美工,苦了想修改代码的程序员,Discuz基本上全部都是采用的这种方法来进行页面输出。呵呵。。大家有得玩了。

不过我发现在这里用到了大量的转义字符,他们为什么不用@号哪???想不通。。呵呵。。。

不过性能方面不知道如何,有机会我想试一试。

跳转语句采用了:

   1:  <input type="button" onclick="javascript:window.location.href='step2.aspx';" value="下一步">
 
原文地址:https://www.cnblogs.com/chu888chu888/p/1256554.html