Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 函数中的Request.ServerVariables_C#_Asp.net - Fatal编程技术网

C# 函数中的Request.ServerVariables

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

CS0120:非静态字段需要对象引用, 方法或属性“System.Web.UI.Page.Response.get”


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);
}