zoukankan      html  css  js  c++  java
  • .NET 配置文件实用指南

      我想大家对配置文件一定不会陌生,在大部分的项目中都会用到它,在此笔者给出一些配置文件的实用示例。

    • XML配置文件

         利用XML格式的配置文件储存连接字符串,再用反射技术读取。

    using System.Reflection;

    String str = ConfigurationManager.AppSettings["DemoKey"].Value;
    • Config文件

         .NET程序系统读取config文件配置是在全计算机范围内,如果有两个config文件中有相同的name但是有不同键值的话,程序在加载配置时就会出现错误

    using System.Configuration;
    string conStr=ConfigurationManager.ConnectionStrings["SqlConStr"]. ConnectionString.ToString();
      
    • .NET4.0模式
    <configuration>
      <startup useLegacyV2RuntimeActivationPolicy ="true ">
        < requiredRuntime safemode ="true " imageVersion ="v4.0 " version ="v4.0 "/>
        < supportedRuntime version ="v4.0 " sku ="client " />
      </startup>
    </configuration>

     

    • .NET2.0与4.0兼容模式
    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
    </configuration>
     
    • 取消页面注入防范功能
        要将网站.net版本设置为4以上,不然无法配置。
    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <httpRuntime requestValidationMode="2.0"/>
    </system.web>
  • 相关阅读:
    A. Maze
    A. Ice Skating (联通块)
    A. DZY Loves Chessboard (找到一个涂一个)
    C. Kefa and Park
    A. Party
    N皇后问题
    八皇后问题
    A. DZY Loves Sequences
    A. Reorder the Array (二分变形)
    BZOJ1681 [Usaco2005 Mar]Checking an Alibi 不在场的证明
  • 原文地址:https://www.cnblogs.com/liusuqi/p/3216344.html
Copyright © 2011-2022 走看看