一些對象或是方法,如Session, Response,Server等等,無法在類別中直接打,是因爲沒有在類別中引用它們的名稱空間。這個名稱空間(namespace):System.Web。另外它們正確的寫爲HttpContext.Current.Session,HttpContext.Current.Response 和HttpContext.Current.Server。
參考:
using System.Web;
/// <summary>
/// Summary description for CodeDemo
/// </summary>
public class CodeDemo
{
public CodeDemo()
{
//
// TODO: Add constructor logic here
//
}
//下面列舉了幾個對象與方法
public void t()
{
HttpContext.Current.Session["mykey"] = "Session content";
HttpContext.Current.Response.Write("Write content.");
HttpContext.Current.Server.MapPath(@"z:\...\");
}
}