I’m working on a C# library class which is being consumed by an ASP.NET 4.0 Web Forms application. In my class, I’m trying to access the HttpRequest.Application object as described here:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx
This documentation says it is in the System.Web namespace but even when I add a reference in my library project, it is still not available to me.
The only way I can get to the ApplicationPath property is by using:
HttpContext.Current.Request.ApplicationPath;
What’s going on?
ApplicationPathis not a static property onHttpRequest, which is why you have to access it using the instanceHttpContext.Current.Request. If you don’t want to useHttpContext.Current.Requestyou could always pass theHttpRequestobject in to your class library from your ASP.NET web forms.For example (from your Page_Load):