ASP.Net会话状态未正确启用

ASP.Net会话状态未正确启用,asp.net,web-config,session-state,Asp.net,Web Config,Session State,我在ASP.Net应用程序中无法使会话状态正常工作。我在所有的指令中都设置了EnableSessionState=“true”,但似乎每个页面上都有不同的会话ID 我使用的母版页找不到为其指定EnableSessionState的方法(我假设使用它的页面有会话状态,那么它有吗?) 我已经在我的Web.config中设置了元素,以便在cookies中使用InProc会话状态,但这似乎没有任何效果-我正在运行IIS 7,因此我希望部分被忽略,而部分被忽略,并且在该部分中似乎没有会话状态的等效配置元素

我在ASP.Net应用程序中无法使会话状态正常工作。我在所有的
指令中都设置了
EnableSessionState=“true”
,但似乎每个页面上都有不同的会话ID

我使用的母版页找不到为其指定EnableSessionState的方法(我假设使用它的页面有会话状态,那么它有吗?)

我已经在我的Web.config中设置了
元素,以便在cookies中使用InProc会话状态,但这似乎没有任何效果-我正在运行IIS 7,因此我希望
部分被忽略,而
部分被忽略,并且在该部分中似乎没有会话状态的等效配置元素(或者不明显)

我曾尝试在谷歌上搜索这方面的内容,但似乎找不到确切解释我需要做什么才能在整个应用程序中启用会话状态并正常工作的方法。有什么想法吗

我的Web.config文件如下,如果需要,我可以发布更多详细信息

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                    <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
                    <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                    <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                    <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                </sectionGroup>
            </sectionGroup>
        </sectionGroup>
    </configSections>
    <appSettings>
        <add key="DBServer" value="localhost"/>
        <add key="DBName" value="bbcdemo"/>
        <add key="DBUser" value="example"/>
        <add key="DBPassword" value="password"/>

    <add key="DemoEndpoint" value="http://nottm.ecs.soton.ac.uk/BBCDemo/sparql/"/>

    <add key="/BBCDemo/sparql/" value=""/>
    <add key="LoadMode" value="PreloadAllAsync" />
    <add key="DefaultQueryFile" value="~/App_Data/default.rq"/>
    <add key="Stylesheet" value="/BBCDemo/bbcdemo.css"/>

    <add key="RewriteRuleFind1" value="^.*programmes/([A-Za-z0-9]+)$"/>
    <add key="RewriteRuleReplace1" value="http://www.bbc.co.uk/programmes/$1#programme"/>

    </appSettings>
    <connectionStrings/>
    <system.web>
        <!-- 
            Set compilation debug="true" to insert debugging 
            symbols into the compiled page. Because this 
            affects performance, set this value to true only 
            during development.
        -->
        <compilation debug="true">
            <assemblies>
                <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
            </assemblies>
        </compilation>
        <!--
            The <authentication> section enables configuration 
            of the security authentication mode used by 
            ASP.NET to identify an incoming user. 
        -->
        <authentication mode="Windows"/>
        <!--
            The <customErrors> section enables configuration 
            of what to do if/when an unhandled error occurs 
            during the execution of a request. Specifically, 
            it enables developers to configure html error pages 
            to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
        </customErrors>
        -->
        <pages>
            <controls>
                <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            </controls>
        </pages>
        <httpHandlers>
            <remove verb="*" path="*.asmx"/>
            <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
        </httpHandlers>
        <httpModules>
            <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </httpModules>
    <sessionState mode="InProc" timeout="20" cookieless="UseCookies" />
    </system.web>
    <system.codedom>
        <compilers>
            <compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
                <providerOption name="CompilerVersion" value="v3.5"/>
                <providerOption name="WarnAsError" value="false"/>
            </compiler>
        </compilers>
    </system.codedom>
    <!-- 
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    -->
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules>
            <remove name="ScriptModule"/>
            <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
        </modules>
        <handlers>
            <remove name="WebServiceHandlerFactory-Integrated"/>
            <remove name="ScriptHandlerFactory"/>
            <remove name="ScriptHandlerFactoryAppServices"/>
            <remove name="ScriptResource"/>
      <remove name="SPARQLHandler"/>
            <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
            <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      <add name="SPARQLHandler" verb="*" path="sparql/" type="VDS.RDF.Web.SPARQLHandler"/>
      <add name="ResourceHandler" verb="*" path="programmes/*" type="VDS.RDF.Web.SQLResourceHandler"/>
        </handlers>
    </system.webServer>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
                <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>


在任何人抱怨我在AppSettings中存储DB设置之前,我应该指出,在生产环境中,我会加密
部分,并且所使用的数据库帐户仅对特定数据库具有(并且需要)只读权限。

设置启用会话状态=true实际上没有多大用处,默认情况下,它位于应用程序范围内。为确保IIS7配置正确,您可以尝试执行以下操作:

如果您在每个页面上都看到一个新的SessionID,那么很可能是因为您的客户端没有存储/转发会话cookie(可能是因为浏览器上的安全限制)。首先验证您确实正在呈现会话cookie,并且所有请求都来自同一域

要验证这不是cookie问题,可以将会话状态切换为使用无cookie模式,以查看后续请求中是否加载了正确的会话:

<sessionState cookieless="UseUri" />

设置EnableSessionState=true实际上没有多大作用,默认情况下它在应用程序范围内。为确保IIS7配置正确,您可以尝试执行以下操作:

如果您在每个页面上都看到一个新的SessionID,那么很可能是因为您的客户端没有存储/转发会话cookie(可能是因为浏览器上的安全限制)。首先验证您确实正在呈现会话cookie,并且所有请求都来自同一域

要验证这不是cookie问题,可以将会话状态切换为使用无cookie模式,以查看后续请求中是否加载了正确的会话:

<sessionState cookieless="UseUri" />

我正在检查Web.Config中的会话状态参数。我认为有一个打字错误。请再次验证web.config并测试

SessionState标记中,无Cookies属性只接受的值“true”或“false”,但您的web.config显示为“UseCookies”



请将cookieless的值设置为false或true,然后重试。。希望这能解决问题。

我正在检查Web.Config中的会话状态参数。我认为有一个打字错误。请再次验证web.config并测试

SessionState标记中,无Cookies属性只接受的值“true”或“false”,但您的web.config显示为“UseCookies”



请将cookieless的值设置为false或true,然后重试。。希望这能解决问题……

这是不正确的。cookieless属性可以有以下6个值之一:自动检测、UseCookies、UseDeviceProfile、UseUri、true、false。有关详细信息,请参阅。这是不正确的。cookieless属性可以有以下6个值之一:自动检测、UseCookies、UseDeviceProfile、UseUri、true、false。有关更多信息,请参阅。似乎与我的问题无关,但可能会在ASPX和ASHX混合时解释类似问题-似乎与我的问题无关,但可能会在ASPX和ASHX混合时解释类似问题-
<sessionState mode="InProc" timeout="20" cookieless="UseCookies" />