|用管道分隔|的处理方式是什么?连接字符串中的变量?

时间:2020-03-05 18:40:15  来源:igfitidea点击:

我知道| DataDirectory |会在ASP.NET应用程序中解析为" App_Data",但是是否采用了硬编码或者是否正在按照%环境变量%的方式使用通用机制?

解决方案

回答

从MSDN智能客户端数据博客:

In this version, the .NET runtime
  added support for what we call the
  DataDirectory macro. This allows
  Visual Studio to put a special
  variable in the connection string that
  will be expanded at run-time...
  
  By default, the |DataDirectory|
  variable will be expanded as follow:
  
  
  For applications placed in a
  directory on the user machine, this
  will be the app's (.exe) folder.
  For apps running under ClickOnce, this will be a special data folder
  created by ClickOnce
  For Web apps, this will be the App_Data folder
  
  
  Under the hood, the value for
  |DataDirectory| simply comes from a
  property on the app domain. It is
  possible to change that value and
  override the default behavior by doing
  this:

AppDomain.CurrentDomain.SetData("DataDirectory", newpath)