473,473 Members | 2,031 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

POST Redirect to another Site

I am trying to create ASPX code which will allow me to redirect a user to
another site with POST data. I figure that the best way to do this is with
JavaScript to the client. Here's what I'm doing:

I have a JavaScript function that looks like this:

function DoPostRedir()
{
document.MainFrm.method = "POST";
document.MainFrm.action = "http://XXX.YYY.com/Help/";
document.MainFrm.submit();
}
In my ASPX CS code, I write a Hidden field to the Form.

But when I try to run this, the destination page of the POST (on a
completely different web server over which I will not have control in the
future) gives me this error:

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

I have a feeling that this has something to do with the fact that I'm
posting to a different server or something? Is it a security thing?

How do I build a nice, clean form and force it to be posted to another site
so that it really only contains the Hidden field of data that I want to pass
along?

Alex

Jun 16 '07 #1
5 6638
I've done a little more experimentation and I've learned this: If I go to the
OTHER site which I am POSTing to and I set EnableViewStateMac="false", I stop
getting the error I mentioned below and everything works perfectly.

The problem is, I cannot control whet the OTHER sites I am POSTing to will
do - in fact, they may not be .NET at all.

In MY page, where I am writing the POST-Redirection JavaScript, I tried
setting EnableViewState="false", and yet when I look at the Page source, I
still have two hidden fields:

1. id="__VIEWSTATE"
2. id="__EVENTVALIDATION"

I think that these are causing the problem. How do I keep ASP.NET from
generating these?

Alex
"Alex Maghen" wrote:
I am trying to create ASPX code which will allow me to redirect a user to
another site with POST data. I figure that the best way to do this is with
JavaScript to the client. Here's what I'm doing:

I have a JavaScript function that looks like this:

function DoPostRedir()
{
document.MainFrm.method = "POST";
document.MainFrm.action = "http://XXX.YYY.com/Help/";
document.MainFrm.submit();
}
In my ASPX CS code, I write a Hidden field to the Form.

But when I try to run this, the destination page of the POST (on a
completely different web server over which I will not have control in the
future) gives me this error:

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

I have a feeling that this has something to do with the fact that I'm
posting to a different server or something? Is it a security thing?

How do I build a nice, clean form and force it to be posted to another site
so that it really only contains the Hidden field of data that I want to pass
along?

Alex
Jun 16 '07 #2

"Alex Maghen" <Al********@newsgroup.nospamwrote in message
news:F7**********************************@microsof t.com...
>I am trying to create ASPX code which will allow me to redirect a user to
another site with POST data. I figure that the best way to do this is with
JavaScript to the client. Here's what I'm doing:

I have a JavaScript function that looks like this:

function DoPostRedir()
{
document.MainFrm.method = "POST";
document.MainFrm.action = "http://XXX.YYY.com/Help/";
document.MainFrm.submit();
}
In my ASPX CS code, I write a Hidden field to the Form.

But when I try to run this, the destination page of the POST (on a
completely different web server over which I will not have control in the
future) gives me this error:

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

I have a feeling that this has something to do with the fact that I'm
posting to a different server or something? Is it a security thing?

seems like it

How do I build a nice, clean form and force it to be posted to another
site
so that it really only contains the Hidden field of data that I want to
pass
along?

Alex

I guess you want to use post so the data posted is not visible?

I also assume that because you say that you will not have access to the
server in the future you do have now?

why not make a page that accepts a query string but does not write to
screen, therefore it will not be visible but it can in return load data into
a session variable then redirect to another page with a POST form. the
second page can then load the form with the data from the session variable
and submit itself to the final page.

Jun 16 '07 #3
Ah, you see, the whole thing is that I need to POST to a series of Sites (not
my own). I don't know what they'll be doing. All I know is the URL of the
page to which I will POST on their site, and they know the FORM Field that
contains that data I am posting to them. That's all.

And everything is now working fine in terms of the JavaScript and all that
EXCEPT that I can'r seem to get rid of these nasty ViewState hidden fields!
"ThatsIT.net.au" wrote:
>
"Alex Maghen" <Al********@newsgroup.nospamwrote in message
news:F7**********************************@microsof t.com...
I am trying to create ASPX code which will allow me to redirect a user to
another site with POST data. I figure that the best way to do this is with
JavaScript to the client. Here's what I'm doing:

I have a JavaScript function that looks like this:

function DoPostRedir()
{
document.MainFrm.method = "POST";
document.MainFrm.action = "http://XXX.YYY.com/Help/";
document.MainFrm.submit();
}
In my ASPX CS code, I write a Hidden field to the Form.

But when I try to run this, the destination page of the POST (on a
completely different web server over which I will not have control in the
future) gives me this error:

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

I have a feeling that this has something to do with the fact that I'm
posting to a different server or something? Is it a security thing?


seems like it

How do I build a nice, clean form and force it to be posted to another
site
so that it really only contains the Hidden field of data that I want to
pass
along?

Alex


I guess you want to use post so the data posted is not visible?

I also assume that because you say that you will not have access to the
server in the future you do have now?

why not make a page that accepts a query string but does not write to
screen, therefore it will not be visible but it can in return load data into
a session variable then redirect to another page with a POST form. the
second page can then load the form with the data from the session variable
and submit itself to the final page.
Jun 16 '07 #4
asp.net always renders __viewstate. this is how it knows if it is a
postback. it know thats is a valid viewstate (rendered with the page and
not modified it is encrypted).

to post to a asp.net site your javascript should delete the viewstate node:

var v = document.getElementById('__VIEWSTATE');
v.parentNode.removeChild(v);

the asp.net will process the request, but IsPostback will be false, and
the data will have to be fetched from the forms collection.

-- bruce (sqlwork.com)

Alex Maghen wrote:
Ah, you see, the whole thing is that I need to POST to a series of Sites (not
my own). I don't know what they'll be doing. All I know is the URL of the
page to which I will POST on their site, and they know the FORM Field that
contains that data I am posting to them. That's all.

And everything is now working fine in terms of the JavaScript and all that
EXCEPT that I can'r seem to get rid of these nasty ViewState hidden fields!
"ThatsIT.net.au" wrote:
>"Alex Maghen" <Al********@newsgroup.nospamwrote in message
news:F7**********************************@microso ft.com...
>>I am trying to create ASPX code which will allow me to redirect a user to
another site with POST data. I figure that the best way to do this is with
JavaScript to the client. Here's what I'm doing:

I have a JavaScript function that looks like this:

function DoPostRedir()
{
document.MainFrm.method = "POST";
document.MainFrm.action = "http://XXX.YYY.com/Help/";
document.MainFrm.submit();
}
In my ASPX CS code, I write a Hidden field to the Form.

But when I try to run this, the destination page of the POST (on a
completely different web server over which I will not have control in the
future) gives me this error:

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

I have a feeling that this has something to do with the fact that I'm
posting to a different server or something? Is it a security thing?

seems like it

>>How do I build a nice, clean form and force it to be posted to another
site
so that it really only contains the Hidden field of data that I want to
pass
along?

Alex

I guess you want to use post so the data posted is not visible?

I also assume that because you say that you will not have access to the
server in the future you do have now?

why not make a page that accepts a query string but does not write to
screen, therefore it will not be visible but it can in return load data into
a session variable then redirect to another page with a POST form. the
second page can then load the form with the data from the session variable
and submit itself to the final page.
Jun 16 '07 #5
Hi Alex,

I agree with Bruce that the ViewState MAC validation is particular provided
by ASP.NET to ensure the VIewState data consistency and detect postback.
Also, you can add the script code (that will remove the hidden __ViewState
element) suggested by Bruce into your existing script. e.g.

======================
<script type="text/javascript">
function cltredirect(url)
{
document.form1.method = "POST";
document.form1.action = url;
var v = document.getElementById('__VIEWSTATE');
v.parentNode.removeChild(v);

document.form1.submit();
}

</script>
====================

this can help avoid MAC validation error if the target redirection url is
of ASP.NET page.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 18 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brendan | last post by:
Hi I just made a script that gets a bunch of login info and I've come across a hurdle that I failed to think about it.. and now think I may have wasted my time... The login info I retreive...
9
by: MDW | last post by:
Say I've got a page - myPage.asp - that expects to see the results of a form's POST operation. If it comes from the form, all is fine. However, if someone were to manually type the address in...
2
by: Asp Help | last post by:
I'm working on a ASP applicatition to create Windows 2000 users. Because I don't want everybody to have access to the site I've changed te security in IIS 5.0 which runs on a windows 2000 Sp4...
3
by: Tim Wade | last post by:
Does anyone have any ideas on how to do an automatic html form post using hidden fields without introducing client-side script nor using a server-side WebRequest by passing the information back up...
8
by: Victor | last post by:
I need to redirect to another web page, but that redirect will include the submission of form data. So, unlike ServerXMLHTTP which stays on the originating web page, I need the script to redirect...
5
by: Tyler | last post by:
I am developing an application which will allow me to automatically sign into an external website. I can currently do a screen scrape using HTTPWEBREQUEST. However I want to just redirect to the...
3
by: gustav | last post by:
Hey there, I have this problem: I´m migrating an ASP site to ASP.NET 1.1, and I find myself stuck because of this Form that has some inputs to access an Extranet... When the user submits, the...
1
by: pmasclark | last post by:
Hello, I created a web site, site A, that redirects to another web site, site B, where a simple web service is hosted. The code to call the web service is simple. oWS.AllowAutoRedirect = True...
56
by: UKuser | last post by:
Hi, I'm not sure if this can be done as I've searched the web and this forum. I am using an online merchant provider and I must post certain variables to their webforms through a form on my...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.