ASP.NET操作web.config
ASP.NET可以利用WebConfigurationManager和直接利用XML方式操作web.config,WebConfigurationManager比较简单,但是清除注释代码。两者操作方式都需要有写权限。
方法一,利用WebConfigurationManager,需要引用System.Web.Configuration.WebConfigurationManager;
添加项:
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Add("key", "valueadd");
config.Save(ConfigurationSaveMode.Modified);
修改项:
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings["key"].Value = "valuemodify";
config.Save(ConfigurationSaveMode.Modified);
删除项:
Configuration config = WebConfigurationManager.OpenWebConfiguration(null);
AppSettingsSection app = config.AppSettings;
app.Settings.Remove("key");
config.Save(ConfigurationSaveMode.Modified);
修改连接项:
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConnectionStringsSection conSection = (ConnectionStringsSection)config.GetSection("connectionStrings");
conSection.ConnectionStrings[Request["type"].ToString()].ConnectionString = Request["connstr"];
config.Save(ConfigurationSaveMode.Modified);
XmlDocument xmldoc = new XmlDocument();
string filename = Common.FilePath("../web.config");
&nbs
相关文档:
asp.net文件上传(0)
2009年04月13日 星期一 下午 06:11
Default.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"& ......
正常操作情况下会有ASP.NET Session丢失的情况出现。因为程序是在不停的被操作,排除Session超时的可能。另外,Session超时时间被设定成60分钟,不会这么快就超时的。
现在我就把原因和解决办法写出来。
ASP.NET Session丢失原因:
由于Asp.net程序是默认配置,所以Web.Config文件中关于Session的设定如下:
< sessi ......
ASP.NET提供了Session对象,从而允许程序员识别、存储和处理同一个浏览器对象对服务器上某个特定网络应用程序的若干次请求的上下文信息。Session对应浏览器与服务器的同一次对话,在浏览器第一请求网络应用程序的某个页面时,服务器会触发Session_onStart事件;在对话超时或者被关闭的时候会触发Session_onEnd 事件。程序员 ......