How to satisfy or bypass view state inspection in Asp.net WebForms in a separate message?

I have a link on a Webforms page that opens in a new window and submits to a form other than the page itself. This is done as follows:

JS:

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

Link:

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

As you can see, this overrides the purpose of the main <form> and tries to send to another page. The thing is that this should send / send to another page, avoiding passing the "myDataId" data as the Get parameter.

The above code will work, but will cause an error due to validation checking.

Question : Is there any way for me to satisfy the requirements here or somehow bypass the validation in the view so that I can publish my data this way?

0
source share
1 answer

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

A simple example of PostToPage1.aspx , which is sent to PostToPage2.aspx (instead of 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> 

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

Too simplified fetch for PostToPage2.aspx (add the correct check):

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

Hth ...

+1
source

Source: https://habr.com/ru/post/1438253/


All Articles