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'
Response
is an instance property on the Page
class, provided as a shortcut to HttpContext.Current.Response
.
Either use an instance method, or use HttpContext.Current.Response.Write
in your static method.
Examples
public static string Call()
{
string ref1 = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"];
HttpContext.Current.Response.Write(ref1);
}
Or
public string Call()
{
string ref1 = Request.ServerVariables["HTTP_REFERER"];
Response.Write(ref1);
}
The mention of a get()
method in System.Web.UI.Page.Response.get
refers to the property's get accessor. Essentially, it is saying that you can't call the get() method on an instance of a type from a static method of a type (which of course makes sense).
As a side note, Response.write(ref1);
should be Response.Write()
(corrected case).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With