简体   繁体   English

ASP.NET 4.0 MAC验证失败

[英]ASP.NET 4.0 MAC validation failure

To begin, I should mention that I'm quite new to C# and ASP.NET 4.0. 首先,我应该提到我对C#和ASP.NET 4.0还是很陌生。 The solution to this problem may be elementary so don't hesitate to ask fundamental questions. 解决这个问题的方法可能很简单,所以请不要问基本问题。

I've inherited an ASP.NET 4.0 application that failed our automated security test because of <page enableViewStateMac="false"> (not my fault). 我继承了一个ASP.NET 4.0应用程序,该应用程序由于<page enableViewStateMac="false"> (不是我的错)而未能通过自动化安全测试。 Of course, I turned it on. 当然,我打开了它。 At that point a very specific pattern of behavior emerged: 那时出现了一种非常具体的行为模式:

1) I can navigate to the application landing page 1)我可以导航到应用程序登录页面

2) attempting to click on any link leaving the landing page results in a "Validation of viewstate MAC failed..." error. 2)尝试单击离开登录页面的任何链接都会导致“验证视图状态MAC失败...”错误。

2a) the exception to this is that clicking on the link that takes me to the landing page (the page I'm already on) works just fine 2a)例外情况是,单击将我带到着陆页(我已经在其上的页面)的链接就可以了

I should mention that navigation to other ASPs occurs by way of Response.Redirect(...). 我应该提到,通过Response.Redirect(...)可以导航到其他ASP。 I can successfully navigate to a page if I enter the url directly into the nav bar ( http://dummyhost.com:12345/Enroll.aspx as opposed to http://dummyhost.com:12345/LandingPage.aspx and then clicking on enroll). 如果直接将网址输入到导航栏( http://dummyhost.com:12345/Enroll.aspx ,而不是http://dummyhost.com:12345/LandingPage.aspx ,则可以成功导航到页面),然后单击在注册上)。

In the Page_Init() method of the master page, I'm setting: 在母版页的Page_Init()方法中,我正在设置:

Page.ViewStateUserKey = Session.SessionID;

If I comment out this line, I can turn on MAC and the application is perfectly happy. 如果我注释掉这一行,则可以打开MAC,该应用程序将非常令人满意。 Can anyone illuminate what's going on? 谁能阐明正在发生的事情?

The most likely cause is that some landing-page-specific data is being submitted to the server and persisting through the call to Response.Redirect, so the enrollment page tries to read the landing-page-specific data and fails the request since the data cannot be interpreted correctly. 最可能的原因是某些登陆页面特定的数据正在提交给服务器,并通过对Response.Redirect的调用而保持不变,因此注册页面尝试读取特定于登陆页面的数据,但由于该数据而导致请求失败无法正确解释。

Instead of using Response.Redirect, consider using <a href="Enroll.aspx">...</a> directly in your markup when you want to generate a simple link. 如果要生成简单的链接,请考虑直接在标记中使用<a href="Enroll.aspx"> ... </a>,而不是使用Response.Redirect。 This will cause the browser to make a vanilla HTTP GET request to the specified resource, free of any current-page-specific date. 这将导致浏览器向指定的资源发出原始HTTP GET请求,而没有任何当前页面特定的日期。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM