ASP的奇怪缓存(?)问题。Net MVC

时间:2020-12-30 03:51:37

Having an odd problems with ASP MVC deployed on IIS6 (Windows 2003). I've simplified the controller code to the below;

在IIS6 (Windows 2003)上部署了一个奇怪的ASP MVC问题。我已经简化了下面的控制器代码;

<AcceptVerbs(HttpVerbs.Get)> _
Public Function CloseBatches() As ActionResult
    ViewData("Title") = "Close Batches"
    ViewData("Message") = Session("Message")
    Return View()
End Function

<AcceptVerbs(HttpVerbs.Post)> _
Public Function CloseBatches(ByVal RequestId As String) As ActionResult

    Session("Message") = "Yadda yadda blah"

    Return RedirectToAction("CloseBatches")

End Function

The controller did originally do more, of course, but stripped it to this to try to troubleshoot. The page has the basic ViewPage html (master page reference, etc) and then;

当然,控制器最初确实做了更多的工作,但将其简化为这个以尝试进行故障排除。页面有基本的ViewPage html (master page reference等),然后;

<p><%=ViewData("Message")%></p>
<%Using Html.BeginForm("CloseBatches", "Home", New With {.RequestId = "Close"})%>
    <input type="submit" id="Close" value="Close"/>
<%End Using%>

As you can see I'm trying to go with the Post-Redirect-Display pattern which seems to be the way to go at the moment. The trouble is the when you click the button the message doesn't appear, no matter how many times you click the button. However, if you do a refresh/F5 the text does appear - then refresh again and it disappears - refresh again and it appears - repeat!

正如您所看到的,我正在尝试使用后直接显示模式,这似乎是目前的发展方向。麻烦的是,当你点击按钮时,消息不会出现,不管你点击了多少次按钮。然而,如果你做一个refresh/F5,文本就会出现-然后refresh,它就会消失- refresh,然后它就会出现- repeat!

I've had breakpoints on both controller functions and it hits them at the correct points, I've stepped through the code and no errors are happening so the ViewData should be populated, but the page just doesn't always show it!

我在这两个控制器函数上都有断点,它会在正确的点上击中它们,我遍历了代码,没有发生错误,所以应该填充ViewData,但是页面并不总是显示它!

Tested with IE7 and FF3 - the latter seems a bit more intermittent in that it does occasionally work!

使用IE7和FF3进行测试——后者似乎更断断续续,因为它偶尔会工作!

Any ideas? Something obvious I'm missing? Could some weird caching be going on?

什么好主意吗?明显我失踪吗?是否会出现一些奇怪的缓存?

Thanks.

谢谢。

4 个解决方案

#1


2  

Change your code as follows:

更改代码如下:

<AcceptVerbs(HttpVerbs.Get)> _
Public Function CloseBatches() As ActionResult
    ViewData("Title") = "Close Batches"
    Return View()
End Function

<AcceptVerbs(HttpVerbs.Post)> _
Public Function CloseBatches(ByVal RequestId As String) As ActionResult
    TempData("Message") = "Yadda yadda blah"
    Return RedirectToAction("CloseBatches")
End Function

<p><%=ViewData.Eval("Message")%></p>
<%Using Html.BeginForm("CloseBatches", "Home", New With {.RequestId = "Close"})%>
    <input type="submit" id="Close" value="Close"/>
<%End Using%>

Note that ViewData.Eval says "Get the value from ViewData if it's there, or TempData if it isn't." It's the right place to look for Message.

注意,显示数据。Eval说:“如果ViewData存在,就从它获取值;如果不存在,就从TempData获取值。”这是寻找信息的好地方。

I don't use Session at all in my MVC apps.

我在MVC应用程序中根本不使用会话。

#2


0  

I don't really know about what problem you are facing, but try to use TempData instead of Session.

我不太清楚您面临的问题是什么,但是请尝试使用TempData而不是Session。

#3


0  

I am facing the same problem, I think I've narrowed it down to occur only when I use RedirectToAction. Sometimes it works, and sometimes it does not. It seems to work as expected in IE7 but in FF3 it isn't.

我也面临着同样的问题,我认为只有当我使用RedirectToAction时才会出现这种情况。有时行得通,有时行不通。它在IE7中似乎可以正常工作,但在FF3中却不能。

I have tried both of these methods in my Master Page to check if this value is set

我在主页中尝试了这两个方法,以检查是否设置了这个值

TempData.ContainsKey("Error") 

and

ViewData.Eval("Error")

#4


0  

Sorry, should have mentioned I was originally using TempData but swapped to using Session to make sure the Message data was there for every request to simplify testing. In stepping through it is indeed there, and goes through the ViewData("Message") = Session("Message") bit every time and the debugger shows ViewData as having a Message item in it. The

不好意思,应该提到我最初使用的是TempData,但是交换到使用会话以确保每个请求都有消息数据来简化测试。在执行过程中,它确实存在,并且每次都通过ViewData(“Message”)=会话(“Message”),而调试器显示ViewData中有一个消息项。的

bit on the page isn't conditional in anyway so it should display said ViewData...but it doesn't, or at least not all the time.

I will look into the .Eval bit to see if that solves anything. Thanks.

我将查看. eval位,看看它能否解决任何问题。谢谢。

#1


2  

Change your code as follows:

更改代码如下:

<AcceptVerbs(HttpVerbs.Get)> _
Public Function CloseBatches() As ActionResult
    ViewData("Title") = "Close Batches"
    Return View()
End Function

<AcceptVerbs(HttpVerbs.Post)> _
Public Function CloseBatches(ByVal RequestId As String) As ActionResult
    TempData("Message") = "Yadda yadda blah"
    Return RedirectToAction("CloseBatches")
End Function

<p><%=ViewData.Eval("Message")%></p>
<%Using Html.BeginForm("CloseBatches", "Home", New With {.RequestId = "Close"})%>
    <input type="submit" id="Close" value="Close"/>
<%End Using%>

Note that ViewData.Eval says "Get the value from ViewData if it's there, or TempData if it isn't." It's the right place to look for Message.

注意,显示数据。Eval说:“如果ViewData存在,就从它获取值;如果不存在,就从TempData获取值。”这是寻找信息的好地方。

I don't use Session at all in my MVC apps.

我在MVC应用程序中根本不使用会话。

#2


0  

I don't really know about what problem you are facing, but try to use TempData instead of Session.

我不太清楚您面临的问题是什么,但是请尝试使用TempData而不是Session。

#3


0  

I am facing the same problem, I think I've narrowed it down to occur only when I use RedirectToAction. Sometimes it works, and sometimes it does not. It seems to work as expected in IE7 but in FF3 it isn't.

我也面临着同样的问题,我认为只有当我使用RedirectToAction时才会出现这种情况。有时行得通,有时行不通。它在IE7中似乎可以正常工作,但在FF3中却不能。

I have tried both of these methods in my Master Page to check if this value is set

我在主页中尝试了这两个方法,以检查是否设置了这个值

TempData.ContainsKey("Error") 

and

ViewData.Eval("Error")

#4


0  

Sorry, should have mentioned I was originally using TempData but swapped to using Session to make sure the Message data was there for every request to simplify testing. In stepping through it is indeed there, and goes through the ViewData("Message") = Session("Message") bit every time and the debugger shows ViewData as having a Message item in it. The

不好意思,应该提到我最初使用的是TempData,但是交换到使用会话以确保每个请求都有消息数据来简化测试。在执行过程中,它确实存在,并且每次都通过ViewData(“Message”)=会话(“Message”),而调试器显示ViewData中有一个消息项。的

bit on the page isn't conditional in anyway so it should display said ViewData...but it doesn't, or at least not all the time.

I will look into the .Eval bit to see if that solves anything. Thanks.

我将查看. eval位,看看它能否解决任何问题。谢谢。