Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
System.AppDomain.CurrentDomain.BaseDirectory
this works on localhost but when deploy on server it's not working but when I using

C#
System.Web.HttpContext.Current.Server.MapPath
then that works..!!
Posted
Comments
John C Rayan 28-Oct-15 8:14am    
what do you mean by System.AppDomain.CurrentDomain.BaseDirectory not working?
Member 11774876 28-Oct-15 8:35am    
I mean when I test for particular image to see if that image is exist then ...CurrentDomain.BaseDirectory unable to find(Returns false even though image is present there)but when I test with ...Server.MapPath() then it returns true as file/image found.

1 solution

Both are return the same value most of case but they have some deference.
C#
System.AppDomain.CurrentDomain.BaseDirectory

Get the base directory that the assembly resolver uses to probe for assemblies
Security: for access to the information in the path itself, including if the path is in the form "file://" or \\UNC\dir or "c:\"

C#
System.Web.HttpContext.Current.Server.MapPath

return the physical path of you application that correspond to the specified virtual path on the web server.

In Visual studio 2010 test projects, if you enable deployment option of Edit test settings, AppDomain.CurrentDomain.BaseDirectory points to the TestResults\Out folder(not bin\debug). Although, default setting point to bin\debug folder.
 
Share this answer
 
v2
Comments
Member 11774876 28-Oct-15 8:44am    
But please can your clarify little bit more for line "Get the base directory that the assembly resolver uses to probe for assemblies
Security:"..!!
Debojyoti Saha 28-Oct-15 9:08am    
To successfully deploy your .NET Framework application, you must understand how the common language runtime locates and binds to the assemblies that make up your application. By default, the runtime attempts to bind with the exact version of an assembly that the application was built with. This default behavior can be overridden by configuration file settings.
BaseDirectory return the location which is assembly resolver use.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900