簡體   English   中英

在具有URL路由的ASP.NET 4.0中驗證視圖狀態MAC失敗

[英]Validation of viewstate MAC failed in ASP.NET 4.0 with URL Routing

我得到了臭名昭著的錯誤

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

經過廣泛的搜索,我找不到解決我的特定問題的任何東西。 我在.NET 4中使用URL路由,但未使用MVC。 我發現所有類似的問題/解決方案(由於URL路由)在MVC中提供了解決方案,但在常規ASP.NET Web窗體中卻未提供。

堆棧溢出問題在這里指出:

它似乎與url中子路徑的數量有關。 如果至少有2個子路徑,則視圖狀態驗證失敗。

在測試該理論時,我可以通過簡單地更改我的路線來提供快速而骯臟的解決方法

Module/Search/Results

Module/SearchResults

暫時解決了該問題,但是該帖子中的所有答案都沒有幫助。

我發現有趣的是,該錯誤可以在IE9中重現,但不能在Chrome 24.0.1313.52m中重現。 這使我相信此錯誤是特定於瀏覽器的,因此我嘗試為我的站點設置NoCache,但無濟於事,Chrome仍然有效,IE9仍然拋出ViewState錯誤。

為了重現該問題,以下是影響我的環境的一些關鍵因素:

Windows 7 64-bit
IIS 6.1 SP 1
Local Web Project (VS 2010)
Nested Master Pages (3 levels)
URL Routing (defined in Global.asax)
Page contains a GridView with a TemplateField.  
GridView has PagerSettings defined.
Links causing the error are within the TemplateField.
Links outside of the GridView do not cause the error.

重現步驟如下:

User browses to page "~/Module/Search/Results" (from link or directly doesn't matter)
User clicks on a button that posts back and causes a redirect to another page "~/Module/DoSomething"
User presses the Back button in the browser which takes them back to "~/Module/Search/Results"
User then proceeds to press a button that causes a post-back which immediately causes the error.

更新:在有關頁面布局的關鍵因素中添加了信息。

我該如何為所有瀏覽器解決此問題,以便在用戶返回頁面然后生成另一條回發信息時,網頁的URL中可以有2個或更多子路徑而不會引起錯誤?

我想到了!

嘗試解決出現錯誤的問題時

Microsoft JScript運行時錯誤:'WebForm_FireDefaultButton'未定義

我發現有一篇文章說我需要在路線表頂部添加以下內容

route.Ignore(“ {resource} .axd / {* pathInfo}”);

這似乎已經解決了我一直在尋找的問題和此問題中的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM