对象引用是所必需的非静态字段,方法或财产字段、静态、所必需、财产

2023-09-03 07:30:35 作者:有那么点后悔

我建我的VS2008 .NET 3.5的时候解决方案收到一封错误 错误1,需要一个对象引用非静态字段,方法或属性System.Web.UI.Page.Request.get

I recieve an error when building my vs2008 .net 3.5 solution Error 1 An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Request.get'

String _XSLTPath = Page.Request.Url.Scheme 
    + "://" 
    + Page.Request.Url.Authority 
    + Page.Request.ApplicationPath.TrimEnd('/') 
    + '/' 
    + "webparts/weatherandtime/weather/xslt/RSSWeatherXSL.xsl";

Page对象似乎绿灯,被higlighting这不是我想要的。可有人怎么回事解释一下吗?

The Page object seems to be higlighting in green which is not what i want. Can someone explain whats going on?

谢谢

推荐答案

您尝试访问非静态属性 Page.Request 没有一个实例。你必须把它的一个实例。像 myPage.Request

You try to access the non-static property Page.Request without an instance. You have to call it on an instance. Something like myPage.Request.