20141111-WCF getting the Web path

Source: Internet
Author: User

in the WCF called in Server.MapPath Get Service Publishing directory path

in the WCF called in Server.MapPath Get Service Publishing directory path

in the WCF want to use the Server.map gets the absolute path to the current service publishing directory. However, when debugging, it is found that:

"System.Web.HttpContext.Current.Server.MapPath (" ... "+ filename);

"when not turned onASP when compatible mode (aspnetcompatibilityenabled= "true") , WCF does not support HttpContext, HttpApplication, most articles suggest modifications < serviceHostingEnvironment aspnetcompatibilityenabled= "true" > enables WCF to use ASP. NET Traditional practices. "

Finally, there are two ways to resolve this:

string T1 = System.Web.HttpContext.Current.Server.MapPath ("~");

// the above-mentioned wording WCF not open aspnetcompatibilityenabled when the

// will because HttpContext.Current = = NULL error occurred ???????

String t2 = System.Web.Hosting.HostingEnvironment.MapPath ("~");

The above notation is not a problem with WCF

1. application.startuppath--gets the path to the executable file that launched the application, not including the name of the executable file.
2. environment.currentdirectory--gets and sets the fully qualified path to the current directory (that is, the directory that the process starts from), just the "current" directory, not necessarily the directory where the exe file resides. After you select a file with Fileopendialog, the directory changes.???
3. application.executablepath--gets the path to the executable file that launched the application, including the name of the executable file.
4. system.appdomain.currentdomain.basedirectory--gets the base directory, which is used by the Assembly resolver to probe assemblies. (used in Windows services)

Ref:http://www.cnblogs.com/guohu/archive/2012/10/20/2732199.html

20141111-WCF getting the Web path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.