博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Web.Config配置

Posted on 2010-09-08 23:26  EVON168  阅读(838)  评论(0编辑  收藏  举报

 

<?xml version="1.0"?>
<!-- 
    注意: 除了手动编辑此文件外,您还可以使用 
    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
    “网站”->“Asp.Net 配置”选项。
    设置和注释的完整列表可以在
    machine.config.comments 中找到,该文件通常位于
      \Windows\Microsoft.Net\Framework\vx.x\Config 中 
-->
<configuration>
  
<appSettings>
    
<add key="mykey" value="myvalue"/>
  
</appSettings>
  
<connectionStrings>
    
<clear/>
    
<add name="DemoConnection" providerName="System.Data.SqlClient" connectionString="data source=.;database=MemberShipDemo;uid=sa;pwd=123123"/>
  
</connectionStrings>
  
<system.web>
    
<!-- 
            设置 compilation debug="true" 可将调试符号插入到
            已编译的页面。由于这会
            影响性能,因此请仅在开发过程中将此值
            设置为 true。
        
-->
    
<compilation debug="true">
    
</compilation>
    
<!--
            通过 <authentication> 节可以配置
            安全身份验证模式,ASP.NET 
            使用该模式来识别来访用户身份。 
        
-->
    
<authentication mode="Forms">
      
<forms name="BeingNet" defaultUrl="~/Default.aspx" loginUrl="~/Login.aspx"/>
    
</authentication>
    
<authorization>
      
<!--<deny users="?"/>-->
    
</authorization>
    
<!--
            如果在执行请求的过程中出现未处理的错误,
            则通过 <customErrors> 节
            可以配置相应的处理步骤。具体而言,
            开发人员通过该节可配置要显示的 html 错误页,
            以代替错误堆栈跟踪。
-->
    
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
      
<error statusCode="403" redirect="NoAccess.htm" />
      
<error statusCode="404" redirect="FileNotFound.htm" />
    
</customErrors>

    
<membership defaultProvider="BeingNetProvider" userIsOnlineTimeWindow="30">
      
<providers>
        
<clear/>
        
<add name="BeingNetProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="DemoConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="BeingNet" requiresUniqueEmail="false" passwordFormat="Clear" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
        
<add name="customprovider" type="MyProviderClass"/>
      
</providers>
    
</membership>
    
<roleManager enabled="true" defaultProvider="BNRoleProvider">
      
<providers>
        
<clear/>
        
<add connectionStringName="DemoConnection" name="BNRoleProvider" type="System.Web.Security.SqlRoleProvider"/>
      
</providers>
    
</roleManager>

    
<siteMap defaultProvider="SiteMapAll" enabled="true">
      
<providers>
        
<clear/>
        
<add name="SiteMapAll" type="System.Web.XmlSiteMapProvider" siteMapFile="~/WebAllMenu.sitemap" securityTrimmingEnabled="true"/>
      
</providers>
    
</siteMap>
    
<!--<anonymousIdentification enabled="true" />-->
    
<profile enabled="true" defaultProvider="BNProfileProvider" automaticSaveEnabled="true">
      
<providers>
        
<clear />
        
<add name="BNProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="DemoConnection" applicationName="BeingNet" />
      
</providers>
      
<properties>
        
<!--<clear />
        <add name="是否短消息通知" type="System.Boolean" defaultValue="true" />
        <add name="每页行数" defaultValue="10" type="System.Int32" serializeAs="ProviderSpecific" />
        <group name="地址信息">
          <add name="邮编" defaultValue="200000" />
          <add name="地址" type="System.String" />
          <add name="联系人电话" />
        </group>
        <add name="收藏" type="MyDataSet" serializeAs="Binary" />
        <add name="Theme" allowAnonymous="true" />
-->
        
<add name="语言" defaultValue="zh-cn" />
      
</properties>
    
</profile>
    
<!--<globalization uiCulture="zh-cn"/>-->
  
</system.web>
  
<location path="Reg.aspx">
    
<system.web>
      
<authorization>
        
<allow users="*"/>
      
</authorization>


    
</system.web>
  
</location>
  
<system.net>
    
<mailSettings>
      
<smtp from="admin@126.com">
        
<network host="smtp.126.com" port="25" userName="admin" password="888888"/>
      
</smtp>
    
</mailSettings>
  
</system.net>
</configuration>

 

 通过代码更新Web.Config数据库连接:

 

 protected void Button3_Click(object sender, EventArgs e)
    {
        
//1.取出web.config中的节点
        
//2.给节点赋值
        
//3.保存web.config
        
        
        System.Configuration.Configuration updateWebConfig 
=
            System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(
"~");//打开根目录下的web.config

        updateWebConfig.ConnectionStrings.ConnectionStrings[
"DemoConnection"].ConnectionString = this.TextBox1.Text;

        updateWebConfig.Save();

     
//  this.LabelInfo.Text = "保存完毕";
    }