首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在asp.net mvc中将数据传递给控制器?

如何在asp.net mvc中将数据传递给控制器?
EN

Stack Overflow用户
提问于 2018-05-21 07:16:36
回答 2查看 603关注 0票数 0

我试图使用TempData在控制器之间传递数据,当我运行我的项目时,会出现以下错误:

SessionStateTempDataProvider类要求启用会话状态。描述:在执行当前web请求时发生了未处理的异常。请查看堆栈跟踪 有关错误及其起源于代码的更多信息。 异常详细信息: System.InvalidOperationException: SessionStateTempDataProvider类要求会话状态为 已启用

这是我的web.config:

代码语言:javascript
复制
  <system.web>
    <customErrors mode="Off">
      <error statusCode="404" redirect="~/View/Shared/NotFountError"/>
      <error statusCode="500" redirect="~/View/Shared/InternalServerError"/>
    </customErrors>
    <authentication mode="None"/>
    <compilation debug="true" targetFramework="4.6.2"/>
    <httpRuntime targetFramework="4.5"/>
  <sessionState mode="InProc" />
  </system.web>
  <system.webServer>
    <staticContent>
      <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="10.00:00:00"/>
    </staticContent>
    <httpProtocol>
      <customHeaders>
        <remove name="Vary"/>
        <add name="Vary" value="Accept-Encoding"/>
      </customHeaders>
    </httpProtocol>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="FormsAuthenticationModule"/>
      <add name="SA.Filter.Filter" type="SA.Filter.Filter"/>
    </modules>
    <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>
    <directoryBrowse enabled="true"/>
  </system.webServer>
EN

回答 2

Stack Overflow用户

发布于 2018-05-21 07:21:57

在默认情况下,运行应用程序的服务器似乎没有启用会话状态。

您可以通过您的web.config在每个应用程序的基础上启用它,只需将其放在文件中:

代码语言:javascript
复制
<system.web>
    ..
    <sessionState mode="InProc" />
</system.web>

这将启用存储会话状态(服务器端)的默认进程方法。

如果这没有帮助,它可能指向另一个问题,但我们需要看到完整的异常信息&堆栈跟踪。

票数 0
EN

Stack Overflow用户

发布于 2018-05-21 08:01:01

代码语言:javascript
复制
Google Solved: I added this attribute to the modules node in the web.config and EVERYTHING magically started working:

<modules runAllManagedModulesForAllRequests="true">

It looks like I'm not alone:
Some sample Links are below for your reference.

http://forums.asp.net/p/1293974/2509190.aspx

http://www.flyvergrillen.dk/2009/03/26/being-trapped-in-iis/

I think my pure MVC project (that worked in Test environment) was too simple and may not have forced the MVC framework to require TempData and SessionState, so that's how I'll explain it away ;-)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50443764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档