简体   繁体   English

VS 2010 Intellisense问题

[英]VS 2010 Intellisense Issue

I'm working on a C# library class which is being consumed by an ASP.NET 4.0 Web Forms application. 我正在研究一个ASP.NET 4.0 Web窗体应用程序正在使用的C#库类。 In my class, I'm trying to access the HttpRequest.Application object as described here: 在我的课程中,我尝试按如下所述访问HttpRequest.Application对象:

http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx 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. 该文档说它在System.Web命名空间中,但是即使我在库项目中添加引用,它仍然对我不可用。

The only way I can get to the ApplicationPath property is by using: 我可以获取ApplicationPath属性的唯一方法是使用:

HttpContext.Current.Request.ApplicationPath;

What's going on? 这是怎么回事?

ApplicationPath is not a static property on HttpRequest , which is why you have to access it using the instance HttpContext.Current.Request . ApplicationPath不是HttpRequest的静态属性,这就是为什么您必须使用实例HttpContext.Current.Request访问它的原因。 If you don't want to use HttpContext.Current.Request you could always pass the HttpRequest object in to your class library from your ASP.NET web forms. 如果您不想使用HttpContext.Current.Request ,则可以始终将HttpRequest对象从ASP.NET Web表单传递到类库中。

For example (from your Page_Load): 例如(从您的Page_Load):

protected void Page_Load(object sender, EventArgs e)
{
    var myClass = new MyClass();
    myClass.MyMethod(this.Request);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM