IIS Express不保留会话数据 [英] IIS Express doesn't keep session data

查看:67
本文介绍了IIS Express不保留会话数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在IIS Express服务器下的Visual Studio 2013中运行的应用程序.问题是会话数据没有保存在页面之间,而我发现之前没有空的对象是空的.如果我编译该应用程序并将其部署到带有IIS的Web服务器上,则它可以正常工作,因此,它必须与IIS Express兼容.我搜索了文档文件夹中的配置文件,但实际上不知道它是什么.

I have an application that I run in Visual Studio 2013 under IIS Express server. The problem is that session data is not kept between pages and I find with null objects that weren't null the page before. If I compile the application and deploy it on a web server with IIS it works normally, so it must be something with IIS Express. I searched the config files in the document folders, but really don't know what it is.

谢谢, 卢克

编辑25/11:我在VS 2013和VS 2010的同一台机器上调试代码,发现代码的行为不同.在执行完后面的代码并构建了页面之后,在VS 2010中,执行结束.在VS 2013中,建立页面后,我再次调用context_BeginRequest(object sender,EventArgs e)方法,该方法将应用程序重定向到起始页面,其中Session.Clear()指令清除会话.现在的问题是:为什么要对context_BeginRequest方法进行此额外的调用?为什么将其重定向到起始页面而不是当前页面?谢谢,卢克.

Edit 25/11: I'm debugging the code on the same machine witn VS 2013 and VS 2010 and I found where the code behaves differently. After the code behind has been executed and the page has been built, in VS 2010 the execution ends. In VS 2013 after the page has been built I get another call to the method context_BeginRequest(object sender, EventArgs e), which redirects the application to the starting page, where the instruction Session.Clear() clears the session. The problem now is: why is there this additional call to context_BeginRequest method? Why does it redirect to the starting page and not to the page it is currently in? Thanks, Luke.

推荐答案

我遇到了类似的问题.我的代码在生产服务器上运行良好,但是当我在测试计算机上对其进行调试时,保存和重定向之间的会话为空.

I was having a similar problem. My code was running fine on a production server, but when I debugged it on my test machine, the session would be null between saving and redirects.

当我将会话状态设置为无cookie,<sessionState cookieless="true"时,会话变量将被保留.不过,这是不希望的,因为它会将会话名称添加到url中.

When I set the session state to cookieless, <sessionState cookieless="true", the session variable would be retained. This was undesireable though because it adds the session name to the url.

进一步检查时,我注意到system.web中有一行.<httpCookies requireSSL="true" />当我注释掉时,一切正常.

Upon further review, I noticed a line in my system.web <httpCookies requireSSL="true" /> When I commented it out, everything worked as usual.

问题是我的生产IIS服务器使用https://托管代码,而我的测试IIS Express服务器仅使用http.所以我不安全的cookie被丢弃了.

The problem was that my production IIS server was hosting the code using https://, while my test IIS Express server was only using http. So my unsecure cookies were getting discarded.

这篇关于IIS Express不保留会话数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆