我的代码如下:(这是在一个MasterPage页的page_Load里)
if (!Page.IsPostBack)
        {
            if (Session["ACRA_NO"] == null)
            {
                if (Page.User.Identity.Name != null && Page.User.Identity.Name != string.Empty)
                {
                    ADService.ADWebService adws = new ADService.ADWebService();
                    DataSet userDetail = adws.GetESUserInfoByUserID(Page.User.Identity.Name);
                    if (userDetail.Tables[0] != null)
                    {
                        if (userDetail.Tables[0].Rows.Count != 0)
                        {
                            if (userDetail.Tables[0].Rows[0]["USER_TYPE"] != null && userDetail.Tables[0].Rows[0]["USER_TYPE"].ToString() == "4")
                                Session["ACRA_NO"] = userDetail.Tables[0].Rows[0]["COMPANY_ID"] == null ? "" : userDetail.Tables[0].Rows[0]["COMPANY_ID"].ToString();
                        }
                    }
                }
            }
        }
然后我在一个页面里注册,并写属性如下:<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="ComplaintForm.aspx.cs" Inherits="ComplaintForm" Title="Untitled Page" %>public string ACRA_NO
    {
        set { Session["ACRA_NO"] = value; }
        get
        {
            if (Session["ACRA_NO"] != null)
                return Session["ACRA_NO"].ToString();
            else
                return string.Empty;
        }
    }当我取ACRA_NO值时出误如下:
Session state can only be used when enableSessionState is set to true,...
请问是怎么回事?

解决方案 »

  1.   

    <%@ Page enableSessionState ="true"
      

  2.   

    在web.config或者页面里面启用Session
      

  3.   

    问:我为什么会获得这样的错误信息“Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive”?
    答:这个问题可能在一个已经安装了Microsoft Visual Studio .NET开发环境的机器上,再安装Window Sharepoint Server(WSS)后出现。
    WSS ISAPI过滤器会处理所有的请求。当你通过虚拟目录浏览一个ASP.NET的应用程序时,ISAPI过滤器不会给文件夹目录分配URL。
    解决方法是:不要再安装了WSS的机器上使用Session。
    详细信息请参考:
    Session state cannot be used in ASP.NET with Windows SharePoint Serviceshttp://support.microsoft.com/default.aspx?scid=kb;en-us;837376
      

  4.   

    web.config加上
    <sessionState
      mode="InProc"
      stateConnectionString="tcpip=127.0.0.1:42424"
      sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
      cookieless="false"
      timeout="20"
    />或者<%@ Page EnableSessionState="true" ....%>