zoukankan      html  css  js  c++  java
  • 在Arvixe主机部署ASP.net程序 , web.config 写法

    Arvixe主机是看不到 c盘或d盘的, 所有操作都是通过 Control Panel ,地址是

    Address:  
    http://cp.meijinaiwo.com
    Alternate Address:

    http://cp.dock.arvixe.com
    Alternate Address (HTTPS):

    https://cpdock.arvixe.com
    Username:  
    Password:

    --------------------------------------------------

    Add web site 以后, 系统会自动生成一个 web.config 在新网站的目录下 , 不能用开发环境的 web.config替换这个文件,只能改写它, 比较关键的是 connectionString的设置,经多次尝试,发现正确的方法是:

    先建立数据库 和 用户

    1 : 最初是 web.config 是这个样子的:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <directoryBrowse enabled="true" />
            <defaultDocument>
                <files>
                    <clear />
                    <add value="Default.aspx" />
                    <add value="index.php" />
                    <add value="Default.html" />
                    <add value="Default.htm" />
                    <add value="Default.asp" />
                    <add value="index.pl" />
                    <add value="Default.cshtml" />
                    <add value="index.htm" />
                    <add value="index.html" />
                    <add value="index.cshtml" />
                </files>
            </defaultDocument>
            <httpProtocol>
                <customHeaders>
                    <clear />
                </customHeaders>
            </httpProtocol>
        </system.webServer>
    </configuration>

    2 : 如果要改首页 , 可以这样做:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
        <system.webServer>
            <directoryBrowse enabled="true" />
            <defaultDocument>
                <files>
                    <clear />
                    <add value="aspMain.aspx" />
                </files>
            </defaultDocument>
            <httpProtocol>
                <customHeaders>
                    <clear />
                </customHeaders>
            </httpProtocol>
        </system.webServer>
    
    
    </configuration>

    3 : connectionString的设置,加:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    
        <system.webServer>
            <directoryBrowse enabled="true" />
            <defaultDocument>
                <files>
                    <clear />
                    <add value="aspMain.aspx" />
                </files>
            </defaultDocument>
            <httpProtocol>
                <customHeaders>
                    <clear />
                </customHeaders>
            </httpProtocol>
        </system.webServer>
    
    
           <connectionStrings>
           <add name="ApplicationServices" connectionString="Data Source=localhost;Initial Catalog=databaseName;  Integrated Security=false;User ID=username;Password=password" />
           </connectionStrings>
    </configuration>
    Catalog 是 建的数据库名字,User ID 和 Password 是 建的用户名和密码

    注意不能写成
    Integrated Security=True  , 然后不带用户名密码
    同时 , 为了配合这种写法 , 在asp程序中 , 取连接字符串 就应该是这样 :

    string sConnection = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString; 

    注意 这里的 ApplicationServices  要和 web.config 里的 add name="ApplicationServices" 名字一样

    这样就能连接成功了 。

    -----------------------------

    有人是把 connectionString 放到asp程序的setting里,然后在asp程序中 ,用

    string sConnection = Properties.Settings.Default.DBConnection;

    取连接字符串, 这样就和web.config的写法不配套, 也就无法连接了。 (DBConnection 是 setting 的一个自建属性名字)

    如果一定要按照这种写法, 那 web.config 应该是类似这样:

      <applicationSettings>
        <appName.Properties.Settings>
          <setting name="DBConnection" serializeAs="String">
            <value>Data Source=localhost,1440;Initial Catalog=databaseName;User ID=username;Password=password</value>
          </setting>
        </appName.Properties.Settings>
      </applicationSettings>

    但是这样的写法在 arvixe主机上是报错的,不知道什么原因,似乎是不认 这个关键字: applicationSettings

     
  • 相关阅读:
    图片上传-下载-删除等图片管理的若干经验总结3-单一业务场景的完整解决方案
    图片上传-下载-删除等图片管理的若干经验总结2
    HDU 1195 Open the Lock
    HDU 1690 Bus System
    HDU 2647 Reward
    HDU 2680 Choose the best route
    HDU 1596 find the safest road
    POJ 1904 King's Quest
    CDOJ 889 Battle for Silver
    CDOJ 888 Absurdistan Roads
  • 原文地址:https://www.cnblogs.com/lthxk-yl/p/3687715.html
Copyright © 2011-2022 走看看