簡體   English   中英

Request.ServerVariables函數

[英]Request.ServerVariables in function

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:非靜態字段,方法或屬性'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() (更正的情況)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM