/// <summary> /// 自动检查当前程序的目录状态并保存 /// </summary> /// <param name="forumPath"></param> public static void SaveDntConfigForumPath() { HttpRequest request = HttpContext.Current.Request; string forumPath = request.Url.ToString().Replace("http://" + request.Url.Authority, ""); if (forumPath.IndexOf("install") < 0) { return; } forumPath = forumPath.Substring(0, forumPath.IndexOf("install")); BaseConfigInfo baseConfig = BaseConfigs.GetBaseConfig(); if (baseConfig.Forumpath.Trim() != forumPath) { baseConfig.Forumpath = forumPath; string dntPath = Utils.GetMapPath("~/DNT.config"); if (!Utils.FileExists(dntPath)) { dntPath = Utils.GetMapPath("/DNT.config"); } SerializationHelper.Save(baseConfig, dntPath); BaseConfigs.ResetRealConfig(); Utils.RestartIISProcess(); } }
/// <summary> /// 将用户填写的数据库信息写入DNT.config文件 /// </summary> /// <param name="dataSource">数据库地址</param> /// <param name="userID">数据库账号</param> /// <param name="password">数据库账号密码</param> /// <param name="databaseName">数据库名</param> /// <param name="tablePrefix">表前缀</param> public static void EditDntConfig(string dataSource, string userID, string password, string databaseName, string tablePrefix) { BaseConfigInfo baseConfig = BaseConfigs.GetBaseConfig(); string connectionString = string.Format(@"Data Source={0};User ID={1};Password={2};Initial Catalog={3};Pooling=true", dataSource, userID, password, databaseName); baseConfig.Dbconnectstring = connectionString; baseConfig.Tableprefix = tablePrefix; baseConfig.Dbtype = "SqlServer"; string dntPath = Utils.GetMapPath("~/DNT.config"); if (!Utils.FileExists(dntPath)) { dntPath = Utils.GetMapPath("/DNT.config"); } SerializationHelper.Save(baseConfig, dntPath); DbHelper.ConnectionString = baseConfig.Dbconnectstring; BaseConfigs.ResetRealConfig(); }