views:

28

answers:

1

I have a page that I wish to pass an ID in a querystring to another page

eg

Response.Redirect("~/Account/Login.aspx?CertificateID="+ CertificateTextBox.Text);

but the value in the CertificateTextBox is in the format of Encoding.UTF8

so it can contains character like "ZnbiS69F2g22OeupHw+Xlg=="

When the receiving page gets the QueryString

CertificateTextBox.Text = Request.QueryString["CertificateID"];

the "+" and possible other querystring chars like "?" are stripped!!

so I end up with

Request.QueryString["CertificateID"];

returning

"ZnbiS69F2g22OeupHw Xlg=="

the "+" strinpped!

Is there a way to encode these chars so they are not striped by QuesryString() or do I have to use a session variable??

+3  A: 

You need to encode it for URL formatting for example using HttpServerUtility.UrlEncode(), ex:

var encodedCertID = Server.UrlEncode(CertificateTextBox.Text);
Response.Redirect("~/Account/Login.aspx?CertificateID="+ encodedCertID);
Nick Craver
Ive tried several types of Encoding, but if the "+" is anywhere in a Querystring it is stripped!
@user319675 - That'll happen when you *decode* are you sure you're not running `UrlDecode()` by mistake? When you encode your string should look like this: `"ZnbiS69F2g22OeupHw%2bXlg=="`.
Nick Craver