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>
  • 相关阅读:
    dblink
    linux 查进程、杀进程、起进程
    oracle 资源统计SQL语句
    DIV+CSS+javascript 手动轮播图
    接受同步数据接口
    java String StringBuffer StringBuilder
    SpringMVC Servlet 分页查询接收参数
    WPF 开发
    收集整理的各地精品青年旅舍大全(
    Linux平台Java调用so库JNI使用例子
  • 原文地址:https://www.cnblogs.com/liusuqi/p/3216344.html
Copyright © 2011-2022 走看看