Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass data to a URL on a different web server without the QueryString

I've got an .ashx handler which, upon finishing processing will redirect to a success or error page, based on how the processing went. The handler is in my site, but the success or error pages might not be (this is something the user can configure).

Is there any way that I can pass the error details to the error page without putting it in the query string?

I've tried:

  1. Adding a custom header that contains the error details, but since I'm using a Response.Redirect, the headers get cleared
  2. Using Server.Transfer, instead of Response.Redirect, but this will not work for URLs not in my site

I know that I can pass data in the query string, but in some cases the data I need to pass might be too long for the query string. Do I have any other options?

like image 851
lhan Avatar asked Mar 27 '14 21:03

lhan


People also ask

How do I pass data from one page to another without query string?

If your two pages are on the same domain, you can use HTML5 LocalStorage. It's a JavaScript object that can hold strings up to around 5MB or so. If you need to store other data than strings, you can use JSON. stringify() and JSON.

How do you pass data into a URL?

To add a URL variable to each link, go to the Advanced tab of the link editor. In the URL Variables field, you will enter a variable and value pair like so: variable=value. For example, let's say we are creating links for each store and manager.

How do I pass a URL with multiple parameters into a URL?

To add a parameter to the URL, add a /#/? to the end, followed by the parameter name, an equal sign (=), and the value of the parameter. You can add multiple parameters by including an ampersand (&) between each one.


1 Answers

Essentially, no. The only way to pass additional data in a GET request (i.e. a redirect) is to pass it in the query string.

The important thing to realise is that this is not a limitation of WebForms, this is just how HTTP works. If you're redirecting to another page that's outside of your site (and thus don't have the option of cookies/session data), you're going to have to send information directly in the request and that means using a query string.

Things like Server.Transfer and Response.Redirect are just abstractions over a simple HTTP request; no framework feature can defy how HTTP actually works.

You do, of course, have all kinds of options as to what you pass in the query string, but you're going to have to pass something. If you really want to shorten the URL, maybe you can pass an error code and expose an API that will let the receiving page fetch further information:

  1. Store transaction information (or detailed error messages) in a database with an ID.
  2. Pass the ID in the query string.
  3. Expose a web method or similar API to allow the receiving page to request additional information.

There are plenty of hacky ways you could create the illusion of passing data in a redirect outside of a form post (such as returning a page containing a form and Javascript to immediately do a cross-domain form post) but the query string is the proper way of passing data in a GET request, so why try to hack around it?

like image 112
Ant P Avatar answered Oct 21 '22 06:10

Ant P