管道符变量在连接字符串中有什么作用?

3

我知道在ASP.NET应用程序中,|DataDirectory|会解析为App_Data,但这是硬编码的吗?还是有一种类似于%环境变量%的通用机制在起作用?

1个回答

5

来自 MSDN Smart Client Data Blog

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)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接