gpt4 book ai didi

c# - 函数中的 Request.ServerVariables

转载 作者:行者123 更新时间:2023-11-30 13:48:36 25 4
gpt4 key购买 nike

public static string Call()
{
string ref1 = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];
Response.write(ref1);
}

public void Page_Load(object sender, EventArgs e)
{
Call()
}

CS0120: An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Response.get'

最佳答案

ResponsePage 类的实例属性,作为 HttpContext.Current.Response 的快捷方式提供。

要么使用实例方法,要么在静态方法中使用 HttpContext.Current.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);
}

System.Web.UI.Page.Response.get 中提到的 get() 方法指的是属性的 get 访问器。本质上,它是说您不能从类型的静态方法调用类型实例的 get() 方法(这当然是有道理的)。

作为旁注,Response.write(ref1); 应该是 Response.Write()(更正大小写)。

关于c# - 函数中的 Request.ServerVariables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12188477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com