C# 函数中的Request.ServerVariables
CS0120:非静态字段需要对象引用, 方法或属性“System.Web.UI.Page.Response.get”C# 函数中的Request.ServerVariables,c#,asp.net,C#,Asp.net,CS0120:非静态字段需要对象引用, 方法或属性“System.Web.UI.Page.Response.get” Response是页面类上的一个实例属性,作为HttpContext.Current.Response的快捷方式提供 使用实例方法,或者在静态方法中使用HttpContext.Current.Response.Write 示例 public static string Call() { string ref1 = HttpContext.Current.Request.S
Response
是页面
类上的一个实例属性,作为HttpContext.Current.Response
的快捷方式提供
使用实例方法,或者在静态方法中使用HttpContext.Current.Response.Write
示例
public static string Call()
{
string ref1 = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];
Response.write(ref1);
}
public void Page_Load(object sender, EventArgs e)
{
Call()
}
或
System.Web.UI.Page.Response.get
中提到的get()
方法指的是属性的get访问器。本质上,它是说不能从类型的静态方法调用类型实例上的get()方法(这当然是有意义的)
作为旁注,Response.write(参考文献1)
应该是Response.Write()
(已更正大小写)
public static string Call()
{
string ref1 = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];
HttpContext.Current.Response.Write(ref1);
}
public string Call()
{
string ref1 = Request.ServerVariables["HTTP_REFERER"];
Response.Write(ref1);
}