How to identify data is Encoded using Server.UrlEncode() Asp.net - asp.net

Can we identify whether input data is Encoded using Server.UrlEncode() method or not?
I am looking for something like "Server.IsUrlEncoded"?

This way you check also if url is properly encoded:
string url = "...";
if(Server.UrlEncode(Server.UrlDecode(url)) == url)
{
// do stuff
}

why don't you just decode and encode it regardless then you make sure it's encoded?

Related

how to decode QUrlnfo.name()?

I received the following QUrlInfo string from QFtp::listInfo(QUrlInfo) and the correct URL fragment is actually set to ©®§µ here in a test.
But QUrlInfo.name() returns a String containing ©®§µ. I realize I must encode it somehow, but how do I do that?
This should work:
QString::fromUtf8(info.name().toAscii());

Decode and RequestQueryString

My URL is
www.domainname.com/default.aspx?l=en&t=32600483-1618-4f09-9a86-c12de4dafc7b
I would love to read the QueryString value of t. So i can parse it as GUID.
Unfortunatelly that & thing, seems to mess things up.
How can i parse the value of the t Query string?
My URL is
I hope you realize that this is not a valid URL. This is a HTML encoded string. Do not confuse with an URL. URLs should be properly URL encoded, not HTML encoded. And since you start with something invalid your only chance is to use some ugly string parsing/regex to extract the necessary information. Since this looks like an HTML encoded string you could HTML decode it first:
var myUrl = "http://www.domainname.com/default.aspx?l=en&t=32600483-1618-4f09-9a86-c12de4dafc7b";
myUrl = HttpUtility.HtmlDecode(myUrl);
var values = HttpUtility.ParseQueryString(myUrl);
var t = values["t"];
But I repeat once again: don't do this: tackle the problem at its root. And the root of your problem is the origin of this URL. So if you have control over the generation of this URL then fix it so that you can have a valid URL that you could easily work with with the built-in methods. If you don't have control over the generation of the URL then notify the author of the code that he has a bug in it and ask him to fix it because he has provided you a non-properly encoded URL and you are obliged to use some ugly string parsing mechanisms to extract the information from it.

Encoded ID in URL path on IIS with asp.net

We have an Id that could look something like this:
WIUHyUT/Evg=/
That we would like to use in the path or an url:
http://localhost/freelancers/WIUHyUT/Evg=/Brigitte
This obviously does not work, so we used HttpUtility.UrlEncode() and get
http://localhost/freelancers/WIUHyUT%2fEvg%3d/Brigitte
But this still does not work.
What would be a good approach here?
Once you get the url string back, you have to decode it.
Also, you should use any slashes after encoded params, use ampersand instead to join them.
We actually decided to encode the whole thing into HEX first:
public static string GetBytesToString(byte[] value)
{
SoapHexBinary shb = new SoapHexBinary(value);
return shb.ToString();
}
With this we then just had HEX codes in the url. Works fine.

asp.Net + encrypted QueryString requested not reading '+' sign

I have an encrypted query string passed from another page, it reads something like "/se73j+sef" but after receiving it, the '+' sign got omitted and became "/se73j sef". Is this normal? Please kindly advice. Thanks.
Is this normal?
Yes, perfectly normal. + is a special character in an url. It means space (0x20 ASCII character). If you want to represent the + sign you will have to url encode it:
/se73j%2Bsef
To url encode a string in .NET you could use the UrlEncode method. Or depending on how you are building the url there are certainly better ways.

How do we send data via GET method?

I am creating a HTTPS connection and setting the request property as GET:
_httpsConnection = (HttpsConnection) Connector.open(URL, Connector.READ_WRITE);
_httpsConnection.setRequestMethod(HttpsConnection.GET);
But how do I send the GET parameters?
Do I set the request property like this:
_httpsConnection.setRequestProperty("method", "session.getToken");
_httpsConnection.setRequestProperty("developerKey", "value");
_httpsConnection.setRequestProperty("clientID", "value");
or do I have to write to the output stream of the connection?
or do I need to send the Parameter/Values by appending it to the url?
Calling Connection.setRequestProperty() will set the request header, which probably isn't what you want to do in this case (if you ask me I think calling it setRequestHeader would have been a better choice). Some proxies may strip off or rewrite the name of non-standard headers, so you're better off sticking to the convention of passing data in the GET URL via URL parameters.
The best way to do this on a BlackBerry is to use the URLEncodedPostData class to properly encode your URL parameters:
URLEncodedPostData data = new URLEncodedPostData("UTF-8", false);
data.append("method", "session.getToken");
data.append("developerKey", "value");
data.append("clientID", "value");
url = url + "?" + data.toString();
HTTP GET send data parameters as key/value pairs encoded within URL, just like:
GET /example.html // without parameters
GET /example.html?Id= 1 // with one basic parameter
GET /example.html?Id=1&Name=John%20Doo // with two parameters, second encoded
Note follow rules for character separators:
? - split URL in two pieces: adddress to left and paremeters to right
& - must be used to separate on parameter from another
You must know your platform specific native string encode function. Javascript uses escape, C# uses HttpUtility.UrlEncode
Yep, headers and properties are pretty much all you can send in a GET. Also, you're limited to a certain number of characters, which is browser dependent - I seem to recall about 1024 or 2000, typically.

Resources