zoukankan      html  css  js  c++  java
  • asp.net2.0 中 web.config 的一些改变

              
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Web.Configuration;

    public partial class _Default : System.Web.UI.Page 
    {
        
    protected void Page_Load(object sender, EventArgs e)
        
    {

        }

        
    protected void ShowMessage(string temp)
        
    {
            
    this.Response.Write("<script>alert('" + temp + "')</script>");
        }

        
    //获取 appsetting 的值
        protected void Get_AppSetting_Click(object sender, EventArgs e)
        
    {  
            
    string message=System .Web.Configuration.WebConfigurationManager.AppSettings["message"];

            
    this.ShowMessage(message);

        }

        
    //取得联接字符串的值
        protected void Get_Connection_Click(object sender, EventArgs e)
        
    {
            
    string cnn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["cnn"].ConnectionString  ;
            
    this.ShowMessage(cnn);

        }
     

        
    //用 xpath 方式获取config 中的一section
        protected void Get_Section_Click(object sender, EventArgs e)
        
    {
            Configuration config;

            config 
    = WebConfigurationManager.OpenWebConfiguration("~");

            System.Web.Configuration.IdentitySection section;
            section 
    =config.GetSection("system.web/identity"as System.Web.Configuration.IdentitySection;
            
    if (section != null)
            
    {
              ShowMessage(section.Impersonate.ToString () );  
            }

      


        }

        
    //改变结点信息
        protected void Change_Section_Click(object sender, EventArgs e)
        
    {
            Configuration config;
            config 
    = WebConfigurationManager.OpenMachineConfiguration("~");
            System.Web.Configuration.IdentitySection section;
            section 
    = config.GetSection("system.web/identity"as System.Web.Configuration.IdentitySection;
            
    if (section != null)
            
    {
                section.Impersonate 
    = !section.Impersonate ;
                config.Save();

                ShowMessage(
    "debug setting is now " + section.Impersonate.ToString());

            }


        }


        
    //获取外部数据
        protected void Get_External_Click(object sender, EventArgs e)
        
    {
            
    string cnn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
            
    this.ShowMessage(cnn);
        }

        
    }

    cnn.config
    <connectionStrings>
        
    <add name ="cnn" connectionString ="cnnvalue"/>
        
    </connectionStrings>

    web.config
    <?xml version="1.0"?>
    <!-- 
        Note: As an alternative to hand editing this file you can use the 
        web admin tool to configure settings for your application. Use
        the Website->Asp.Net Configuration option in Visual Studio.
        A full list of settings and comments can be found in 
        machine.config.comments usually located in 
        \Windows\Microsoft.Net\Framework\v2.x\Config 
    -->


    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
        
        
        
        
    <appSettings>
            
    <add key="message" value="hello world"/>
        
    </appSettings>
        
        
        
    <connectionStrings configSource ="cnn.config">
            
        
        
    </connectionStrings>
        
        
    <system.web>
            
    <!-- 
                Set compilation debug="true" to insert debugging 
                symbols into the compiled page. Because this 
                affects performance, set this value to true only 
                during development.
            
    -->
            
    <compilation debug="true" />
            
    <!--
                The <authentication> section enables configuration 
                of the security authentication mode used by 
                ASP.NET to identify an incoming user. 
            
    -->
            
    <authentication mode="Windows"/>
            
    <identity impersonate="true"/>
            
        
            
    <!--
                The <customErrors> section enables configuration 
                of what to do if/when an unhandled error occurs 
                during the execution of a request. Specifically, 
                it enables developers to configure html error pages 
                to be displayed in place of a error stack trace.

            <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
                <error statusCode="403" redirect="NoAccess.htm"/>
                <error statusCode="404" redirect="FileNotFound.htm"/>
            </customErrors>
            
    -->
        
    </system.web>
    </configuration>



    具体可以看这....
    http://odetocode.com/Articles/418.aspx
  • 相关阅读:
    CF1416D Graph and Queries
    Wordpress建站系统相关
    微观经济学
    Preface
    Thread pool in chromium
    [fllutter engine] 并发消息队列
    bugku misc
    python 3.1学习
    HTML&CSS
    DOM技术点
  • 原文地址:https://www.cnblogs.com/gwazy/p/204932.html
Copyright © 2011-2022 走看看