如何满足或在不同的岗位Asp.net的WebForms的ViewState绕过验证? [英] How to satisfy or bypass viewstate validation in Asp.net WebForms on separate post?

查看:137
本文介绍了如何满足或在不同的岗位Asp.net的WebForms的ViewState绕过验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I`ve了在Web表单页面的帖子一个链接,在新窗口中打开,比页面本身以外的其他形式。这是这样做的:

I`ve got a link in a Webforms page which opens in a new window, and posts to a form other than the page itself. This is done like this:

JS:

var submitFunc = function(){
    document.forms[0].action = 'http://urlToPostTo/somePage.aspx';  
    document.forms[0].target = '_blank'; 
    document.forms[0].submit();
}

链接:

<input type="hidden" id="myDataId" value="12345" />     
<a href="javascript:submitFunc();">Search</a>

如你所见,这将覆盖主要的目标&LT;形式为GT; ,并尝试张贴到不同的页面。整点是,这应该发布/提交到不同的页面,同时避免传递myDataId的数据作为的获取的参数。

As you can see, this overrides the target of the main <form>, and attempts to post to a different page. The whole point is that this should post/submit to a different page, while avoiding passing the data of "myDataId" as a Get parameter.

以上code的工作,但会导致错误,由于视图状态验证。

The above code would work, but causes an error due to viewstate validation.

:有什么办法,我要么满足要求在这里,或以某种方式绕过验证视图状态,所以我可以用这种方式张贴我的数据

Question: Is there any way for me to either satisfy the requirements here, or somehow bypass the viewstate validation so I can post my data this way?

推荐答案

听起来像是你只需要改变的 一项PostBackUrl 按钮的那提交表单。

Sounds like you just need to change the PostBackUrl of the button that submits the form.

一个简单的例子 PostToPage1.aspx 的职位为 PostToPage2.aspx (而不是回传):

A simple example PostToPage1.aspx that posts to PostToPage2.aspx (instead of a postback):

<form id="form1" runat="server">
<div>
    <asp:TextBox ID="text1" runat="server" /><br />
    <asp:TextBox ID="text2" runat="server" />
    <asp:Button ID="btn1" runat="server" PostBackUrl="~/PostToPage2.aspx" />
</div>
</form>

您可以再检查请求 PostToPage2.aspx 来检查它是否是一个POST,等再访问在请求的Request.Form 集合的Page_Load

You can then inspect the Request in PostToPage2.aspx to check if it's a POST, etc. and then access the Request.Form collection in the Request in Page_Load.

对于过于简化样品的 PostToPage2.aspx (做正确添加验证):

An overly simplified sample for PostToPage2.aspx (do add proper validation):

if (!Page.IsPostBack && Request.RequestType == "POST")
    {
        if (Request.Form != null && Request.Form.Keys.Count > 0)
        {
           .....

Hth以上...

Hth...

这篇关于如何满足或在不同的岗位Asp.net的WebForms的ViewState绕过验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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