zoukankan      html  css  js  c++  java
  • 整个站点默认禁用 Session,而某个页面不禁用的做法。

    < DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>

    整个站点默认禁用 Session,而某个页面不禁用的做法。

    先说一个不正确的做法:
    整个站点的 Web.config 被设置为:
    <configuration>
    <system.web>
    <sessionState mode="Off"/>
    </system.web>
    </configuration>
    在单独需要用Sesssion的页面,设置
    <%@ Page EnableSessionState="True"%>

    这种做法是错误的,你会发现仍然是错误:

    只有在配置文件或 Page 指令中将启用会话状态设置为真时,才可以使用会话状态
    或者是:
    Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\<system.web>\<httpModules> section in the application configuration.

    后面告诉原因。

    正确的做法是
    Web.config 节sessionState 不要使用下面配置,
    <sessionState mode="Off"/>,
    而是用其他几种配置方式。(不设置的默认配置是 InProc。 )

    然后在在这个 Web.config 中设置
    <configuration>
    <system.web>
       <pages enableSessionState="false" />
    </system.web>
    </configuration>

    这样整个站点的页面默认是不打开Session的。
    在你需要的页面的 使用如下 Page 设置
    <%@ Page EnableSessionState="True"%>

    或者在你需要打开Session的目录下,设置一个 web.config
    <configuration>
    <system.web>
       <pages enableSessionState="true" />
    </system.web>
    </configuration>

    分析原因:
    <sessionState mode="Off"/> 是整个站点禁用了Session,你无法作特列处理。

    另外,通过访问 System.Web.SessionState.HttpSessionState.Mode 属性的值,可以查看当前选定的会话状态。

    上述知识点,不仅仅适用于 ASP.net 1.0 1.1 也适用于 2.0

  • 相关阅读:
    CString to char*
    修改mfc中的图标的问题
    MFC Class Wizard要到这里来找
    多文档情形下,窗口的重绘
    64位的ubuntu跑不了32位下编译出来的代码,可是我就是想跑啊
    ubuntu不能执行某个执行文件,这个叫权限不够
    碰到了在ubuntu下不能读windows盘符的问题——ubuntu使用心得
    画个多边形来,CDC
    如果要在mFC客户区添加控件怎么办
    饿汉单例模式实例——取快递
  • 原文地址:https://www.cnblogs.com/netcorner/p/2912141.html
Copyright © 2011-2022 走看看