Absolute or relative path to the file in web.config

Structure

: ASP.NET

Let's say I have my site located in D: \ Webhome . The structure looks below

D:\Webhome
   |
   |-web.config
   |-default.aspx
   |-folder_1
   |  |- file1
   |
   |-folder_2

I was wondering if it is better to use an absolute or relative path in web.config to link to files. I use the absolute path, but the environment on my workstation is different on the production server, which has a website located in E: \ Web . So I can just copy web.config to my local server. Instead, I simply manually copy the difference.

Another question is how to use the relative path. For instance:

<entry1 name="key1" file="~/folder1/file1">
<entry1 name="key1" file="folder1/file1">
<entry1 name="key1" file="~\folder1\file1">
<entry1 name="key1" file="folder1\file1">

Is there an msdn or document for this? Please advise, thanks.



EDIT:
, . 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() , . ?

+5
3

. E:\web - .

+10

http://msdn.microsoft.com/en-us/library/ms178116.aspx
, ! - . , 1 (, ) default.aspx, :

<img src="folder_1/file1.jpg" />


web.config , :

<authentication mode="Forms">
  <forms loginUrl="~/index.aspx" name="adAuthCookie" path="/">
  </forms>
</authentication>


, , , gl

+3

HttpContext.Server.MapPath( "~/folder_1/file1" ) -.

+1

All Articles