2016-08-12 8 views
0

web.configからどのように動的データを読み取ることが可能ですか?これは私が持っているものです。web.configからデータを読み取る

 <appSettings> 
<add key="TemplatesRootPath" value="System.Web.Hosting.HostingEnvironment.MapPath('~\\PSDtemplates\\MasterTemplates\\')"/></appSettings> 

私はキーTemplatesRootPathの実際の値を取得しようとすると:

var result= WebConfigurationManager.AppSettings["TemplatesRootPath"]; 

私は値タグ」System.Web.Hostingの下に文字列を取得しています.HostingEnvironment.MapPath( '〜\ PSDtemplates \ MasterTemplates \) "という結果になりました。

私は、私が

C:\\Code\\MyProject\\Project.WEBAPI\\MasterTemplates\\ 

答えて

1

のようなものを取得したいと思いweb.configファイルは、あなたのようなC#コードを使用することはできませんXMLファイルであることを望んでいない。そのためSystem.Web.Hosting.HostingEnvironment XMLではありません。

あなたが設定されているが何ができるか「〜\ PSDtemplates \ MasterTemplates \」あなたの価値として、その後、あなたのコードにあなたが言うことができます。

string TemplatesRootPath = WebConfigurationManager.AppSettings["TemplatesRootPath"]; TemplatesRootPath = System.Web.Hosting.HostingEnvironment.MapPath("~\PSDtemplates\MasterTemplates\");

+0

恐ろしいです。どうもありがとう! – ruud

関連する問題