框架:ASP.NET絕對或相對文件路徑在web.config中
說我有我的網站位於d:\ Webhome。該結構是像下面
D:\Webhome
|
|-web.config
|-default.aspx
|-folder_1
| |- file1
|
|-folder_2
我想知道是它更好地使用絕對或相對路徑在web.config中引用的文件。我使用絕對路徑,但工作站中的環境與生產服務器中的環境不同,該服務器的網站位於E:\ Web。所以我可以將我的本地web.config複製到生產服務器上。相反,我只是手動將差異複製過來。
另一個問題是如何使用相對路徑。例如:
<entry1 name="key1" file="~/folder1/file1">
<entry1 name="key1" file="folder1/file1">
<entry1 name="key1" file="~\folder1\file1">
<entry1 name="key1" file="folder1\file1">
是否有msdn或此文檔?請指教,謝謝。
編輯:
它似乎不適合我的情況下工作。我檢查過HttpContext.Server.MapPath(「〜/」),它顯示E:\Webhome
。我的XML在E:\Webhome\QueryDictionary\ITEM.xml
。你能看看有什麼不對嗎?
這是我的web.config
<queryDictionaries>
<queryDictionary name="ITEM" file="~/QueryDictionary/ITEM.xml" type="Com.Data.SqlServer"/>
</queryDictionaries>
這是我得到的錯誤:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\~\QueryDictionary\ITEM.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
at Com.Data.Query.QueryCommander.LoadDictionaries()
EDIT2:
看起來像Com.Data.Query.QueryCommander.LoadDictionaries()
,我必須使用HttpContext.Server.MapPath()
解析文件路徑以獲取絕對路徑。這是原因嗎?
阿門那! :D –
آمين(阿拉伯語中的阿門),這是非常真實的,因爲絕對路徑之後會產生問題。 –