配置文件与网络部署

一、配置文件概述

      1、用途:当一个项目到了发布阶段,需要考虑服务器的迁移,以及站点的安全等问题,这时就需要一个合适的配置文件,对站点进行配置。

      2、基于XML格式的2个配置文件

          a、machine.config(机器配置)

          b、Web.config(站点配置,不需要编译)

      注意:在使用配置文件对ASP.Net站点进行配置时,遵循就近原则

二、数据库连接字符串配置

      1、配置连接字符串

<connectionStrings>
            <add name="SQL" connectionStrings="server=.;database=myDB;uid=sa;pwd=123456;"/>
</connectionStrings>

      2、连接字符串

 public static string connectionString = ConfigurationManager.ConnectionStrings["SQL"].ToString();

      3、数据库连接字符串的加密解密(命令行工具:aspnet_regiis.exe)

      加密语法:

aspnet_regiis.exe -pef section physical_directory -prove provider 

      section:表示加密的配置节
      section physical_directory:用于指定站点的物理路径

      provider:指定加密提供程序(如不指定,则为默认)

      例:aspnet_regiis.exe -pef "connectionStrings" "E:add/web"

    解密语法:

aspnet_regiis.exe -pdf section physical_directory

  注意:只能在同一电脑上进行加密解密

三、自定义错误配置
          在web.config文件的<system.web>中配置(以下是例子)

<customErrors  mode="on" defaultRedirect="~/error/error.htm">

     <error  statusCode="404" redirect="~/error/404.htm">

</customErrors>

    defaultRedirect:指定发生错误时,浏览器重定向到的页面URL

    mode:指定自定义错误的状态。属性值:on表示启用,off表示禁用

    statuCode:HTTP的状态码,404为未找到资源

四、身份验证和授权的配置

      1、身份验证:

            a、Windows验证  默认值  验证性高,但只能用于Windows平台 要求访问者在文本服务器只有一个账号    

  <system.web>
            <authentication mode="Windows">
  </system.web>  

      b、Forms验证  特定网 页      必须从登陆页面登陆

  <system.web>
         <authentication mode="Forms">
//Cookie名 //有效时间
<forms name="user" loginUrl="~/.." timeout="60" ></froms> </authentication> </system.web>

      c、passport验证  网站人员的集中式商业验证服务  单点登陆,需要付费 跨域,跨站点

   <system.web>
          <authentication mode="passport">
      </system.web> 

    2、授权

  <?xml version="1.0" ?>
   <configuration>
         <system.web>
               <authorization>
                 <!--禁止匿名用户-->
                      <deny   users="?">
                    <!--允许管理员角色登陆-->
                       <allow  roles="admin">
                 </authorization>
           /<system.web>
    </ configuration>

五、网站部署

    1、部署:部署前需将web.config配置文件中的调试功能关闭,将<compilation>标签中的debug属性改为false、
      

    2、发布时,选择Release 表示程序已经做完,不能被修改

             选择Debug 调试发布.跨域更改

      

原文地址:https://www.cnblogs.com/yuxiaoyanran/p/3486807.html