Daniel T.
Daniel T.

Reputation: 38390

In ASP.NET, how do I modify POST data and then redirect/POST it to another URL?

I have a page that's sending some POST data in plaintext to an aspx page I wrote:

firstname: John
lastname: Doe
accountid: 123

I need to take this POST data and run it through an encrypting algorithm so the data ends up like so:

firstname: AKFJULKHI
lastname: IDKLNZUI
accountid: RIQLKKNIC

After encoding it, I then need to POST it to another aspx page that's expecting this encoded data. I cannot modify this page. Essentially, I'm writing an in-between page whose purpose is to take some plaintext data, encode it using a proprietary algorithm, and pass it to another page that expects this encrypted data. I realize it's a useless security feature because the user knows what the data is before the encryption, but I cannot modify the other pages and have to stick to the API.

My question is, what is the easiest way of doing this? Response.Redirect will convert it to a GET request, and Server.Transfer will not change the URL on the client side. I could do a manual POST request and then do a Response.Write, but that seems like a really roundabout way of doing it.

Upvotes: 1

Views: 767

Answers (2)

MatthewMartin
MatthewMartin

Reputation: 33143

I think you may want to approach this with a module instead. The HttpModule intercepts the request, can change the request and then the request continues on to the target and the target page is unaware that the request was modified.,

ref: http://www.codeproject.com/Articles/30907/The-Two-Interceptors-HttpModule-and-HttpHandlers#HttpModuletheeventbasedpreprocessor

Upvotes: 2

SLaks
SLaks

Reputation: 887413

HTTP does not support POST redirects.

Instead, you can render a simple page with an HTML form containing hidden inputs with your modified data and pointing to the new URL, then automatically submit the form using Javascript.

Upvotes: 0

Related Questions