當前上下文中不存在名稱"Session"

一些對象或是方法,如Session, Response,Server等等,無法在類別中直接打,是因爲沒有在類別中引用它們的名稱空間。這個名稱空間(namespace):System.Web。另外它們正確的寫爲HttpContext.Current.Session,HttpContext.Current.Response 和HttpContext.Current.Server。

參考:  

代碼
複製代碼
using System;
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:\...\"); 
    }
}
複製代碼
發佈了153 篇原創文章 · 獲贊 7 · 訪問量 75萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章