Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc MVC 5会议问题_Asp.net Mvc_Session_Asp.net Mvc 5 - Fatal编程技术网

Asp.net mvc MVC 5会议问题

Asp.net mvc MVC 5会议问题,asp.net-mvc,session,asp.net-mvc-5,Asp.net Mvc,Session,Asp.net Mvc 5,更新1:如果我通过ajax请求设置会话,那么当js刷新当前操作时,该会话对我不可用。现在,如果我通过非ajax请求设置会话,那么其他控制器甚至ajax操作中也可以使用这些请求 更新2:通过删除和添加会话来帮助解决此问题 <modules runAllManagedModulesForAllRequests="true"> <remove name="Session" /> <add name="Session" type="System.We

更新1:如果我通过ajax请求设置会话,那么当js刷新当前操作时,该会话对我不可用。现在,如果我通过非ajax请求设置会话,那么其他控制器甚至ajax操作中也可以使用这些请求

更新2:通过删除和添加会话来帮助解决此问题

<modules runAllManagedModulesForAllRequests="true">
      <remove name="Session" />
      <add name="Session" type="System.Web.SessionState.SessionStateModule"/>
    </modules>
然而,当我在登录后的同一时刻刷新页面时,我的会话返回为空。在本例中,Request.IsAuthenticated为true,User.Identity.Name中包含我的用户名

我在web.config中也有以下内容

我错过了什么

这是完整的web.config。我在web.config中缺少某些内容,或者某些内容干扰了我的会话

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <!-- Move site specific app settings to their own environment config file inside Configs folder. Keep common settings here -->
  <appSettings file="Configs\AppSettings_CurrentSprint.config">
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>


  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />

    <machineKey validationKey="" validation="SHA1" decryption="AES" />

    <sessionState mode="InProc" timeout="20" />

    <authentication mode="Forms">
      <forms loginUrl="~/EPT/Home" name="SalesSupport.ASPXFORMSAUTH" enableCrossAppRedirects="true" timeout="20" slidingExpiration="true" />
      <!-- timeout="600" -->
    </authentication>
    <membership>
      <providers>
        <clear />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
      </providers>
    </profile>

    <customErrors mode="Off" />

    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="System.Web.Optimization" />


      </namespaces>
    </pages>

  </system.web>

  <system.webServer>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <!--Had to set this for it to work on IIS 7-->
    <modules runAllManagedModulesForAllRequests="true" />

    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <staticContent>
      <!--Required to get IIS to compress javascript files-->
      <remove fileExtension=".js" />
      <mimeMap fileExtension=".js" mimeType="text/javascript" />
    </staticContent>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>


您能解释一下通过ajax创建会话是什么意思吗?您使用的是Ajax.BeginForm还是$Ajax Post或Get?会话由服务器在第一次请求时创建。您可能正在向会话添加对象。可以使用ajax get请求不刷新或创建会话状态(如请求图像)的资源,除非您有有效的身份验证票证,因此响应可能是200状态码。一个简单的测试是在服务器端函数上放置一个断点,然后使用F12调试器观察客户端返回的内容。http post操作对用户进行身份验证,获取用户信息,将用户信息放入会话中,然后向ajax调用发送成功响应。由于这是成功的,ajax刷新了页面。刷新时,我的会话为空。现在,如果我通过标准操作在会话中放置了一些东西,那么它们对我来说是可用的。您的控制器方法是否正在缓存,以便刷新毕竟不是往返的?找到了解决方案,但我仍在寻找“为什么”。。。我需要删除并添加会话。这篇文章有帮助
<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <!-- Move site specific app settings to their own environment config file inside Configs folder. Keep common settings here -->
  <appSettings file="Configs\AppSettings_CurrentSprint.config">
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>


  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />

    <machineKey validationKey="" validation="SHA1" decryption="AES" />

    <sessionState mode="InProc" timeout="20" />

    <authentication mode="Forms">
      <forms loginUrl="~/EPT/Home" name="SalesSupport.ASPXFORMSAUTH" enableCrossAppRedirects="true" timeout="20" slidingExpiration="true" />
      <!-- timeout="600" -->
    </authentication>
    <membership>
      <providers>
        <clear />
      </providers>
    </membership>
    <profile>
      <providers>
        <clear />
      </providers>
    </profile>

    <customErrors mode="Off" />

    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
        <add namespace="System.Web.Optimization" />


      </namespaces>
    </pages>

  </system.web>

  <system.webServer>
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <!--Had to set this for it to work on IIS 7-->
    <modules runAllManagedModulesForAllRequests="true" />

    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
    <staticContent>
      <!--Required to get IIS to compress javascript files-->
      <remove fileExtension=".js" />
      <mimeMap fileExtension=".js" mimeType="text/javascript" />
    </staticContent>
  </system.webServer>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>