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
相关文档:
//TransmitFile实现下载
protected void Button1_Click(object sender, EventArgs e)
{
/*
......
-----------------------------------------------------引言开始-----------------------------------------------------
事情的起因是站点出现未登陆的假象,点着点着就跳到登陆页或提示用户登陆。
因为很多页面都继承了一个PageBase类,这个类会判断用户是否登陆如果没有登陆就会 ......
@Page指令位于每个ASP.NET页面的顶部,告诉ASP.NET这个具体页面使用什么属性,以及该页面继承的用户控件。ASP.NET页面
@Page指令属性有:AspCompat、Async、AsyncTimeout、AutoEventWireup、Buffer、
ClassName、ClientIDMode、CodeBehind、
CodeFile、CodeFileBaseClass、CodePage、CompilationMode 、ContentType、
......
asp.net 获取客户端计算机名
1. 在ASP.NET中专用属性:
获取服务器电脑名:Page.Server.ManchineName
获取用户信息:Page.User
获取客户端电脑名:Page.Request.UserHostName
获取客户端电脑IP:Page.Request.UserHostAddress
2. 在网络编程中的通用方法:
获取当前电脑名:static System.Net.Dns.GetHostNam ......