I have one problem ... I try two days to get QueryString which contains characters which are URL encoded like this %8B%83%94%837n . All that characters are from here http://www.tutorialspoint.com/html/html_url_encoding.htm .
Now when I try to get the QueryString from %8B%83%94%837n I get only the last characters 7n. They are not some special characters which must be encoded. This is work in Asp classic vbscript.
Is anyone has solution for this I would be thankful if help me. Any other solution of this problem is acceptable.
Many thanks :)
MyVar = server.htmldecode(YourQueryString)
MyVar = server.htmlencode(YourQueryString)
Related
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.
We have a asp:DropDownList that we populate server side with
ddlBranch.Items.Add(new ListItem("TEST","This is a's test"));
When this is compiled and run under .NET 3.5 we see the text "This is a's test"
However when this is compiled and run under .NET 4.0 we see the text "This is a's test"
We have added the following to our web.config and there was no change.
<pages controlRenderingCompatibilityVersion="3.5" />
For the time being we have dropped back to .NET 3.5 however we would like to know if there is a way to work around this or if this is a known rendering issue or is by design.
TIA
AJ
Hi All
Thanks for the responses and they led me to look deeper into the code looking for an Encode somewhere. It turns out there that was a:
Server.HtmlEncode(input)
being performed on all controls in a base page class.
Now what I thought was a problem really turns out to be a case of RTFM on my part
From http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes
HtmlEncode and UrlEncode Now Encode Single Quotation Marks
In ASP.NET 4, the HtmlEncode and UrlEncode methods of the HttpUtility and >HttpServerUtility classes have been updated to encode the single quotation mark character >(') as follows:
The HtmlEncode method encodes instances of the single quotation mark as ' .
The UrlEncode method encodes instances of the single quotation mark as %27.
So when I was using .NET3.5 my single quote ( ' ) was being ignored by the HtmlEncode but when switching to .NET 4.0 it was not being ignored by HtmlEncode.
Thanks again for all the responses and work that people put in to this question.
Regards
AJ
When you get the value back you could just HTMLDecode the selected value.
ie. Server.HtmlDecode(ddlBranch.SelectedValue)
Why do you believe this is a problem? ' renders as an apostrophe, and when posted will turn into an apostrophe if that value is selected.
I am new to ASP.NET MVC. I am getting an error when i use these characters - *#%":?<> - in URL.
My question is - Does ASP.NET MVC handle *#%":?<> characters in the URL?
RFC 1738:
Thus, only alphanumerics, the special
characters "$-_.+!*'(),", and reserved
characters used for their reserved
purposes may be used unencoded within
a URL.
Of the characters you listed, only * " and - can theoretically be used unencoded. In practice, many sites would encode all the characters you listed.
No, it does not work, even when you encode them.
It is a stupid limitation in ASP.NET.
They do work in the querystring part though, just not the path part.
Take a look at this.. While it does not solve the problem, at least you know you are not alone :)
Look over here: http://www.w3schools.com/TAGS/ref_urlencode.asp
If you want the chars to be transferred as plain chars, you have to encode them, as they have a meaning in urls.
Use encode in url parameter.
Example:
javascript - window.location = 'path?parameter=' + encodeURIComponent(value);
Razor - #Url.Action("Action", new { parameter=Uri.EscapeUriString(#value) })"
So I have a flashobject which I need to pass a formatted DateTime string to.
My code:
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
which outputs as: 2009-09-16 22:26:45
However when it is actually output to HTML and swfobject it renders it as:
so.addVariable("inNowDate","2009-09-16+22%3a25%3a13");
I think this is messing up a calculation that the flash object does based off the current time. Do I need to encode or decode this?
Any help would be greatly appreciated! Thanks!
It's not that you have gained special characters, but rather certain special characters you already had are now URL encoded.
There's not enough information present for me to see exactly where this URL encoding his happening. Can you post a bit more context?
When you output to html, try using UrlDecode.
http://msdn.microsoft.com/en-us/library/6196h3wt.aspx
I have a query string parameter value that contains an ampersand. For example, a valid value for the parameter may be:
a & b
When I generate the URL that contains the parameter, I'm using System.Web.HTTPUtility.UrlEncode() to make each element URL-friendly. It's (correctly) giving me a URL like:
http://example.com/foo?bar=a+%26b
The problem is that ASP.NET's Request object is interpreting the (encoded) ampersand as a Query String parameter delimiter, and is thus splitting my value into 2 parts (the first has "bar" as the parameter name; the second has a null name).
It appears that ASP.NET is URL-decoding the URL first and then using that when parsing the query string.
What's the best way to work around this?
UPDATE: The problem hinges on URLRewriter (a third-party plugin) and not ASP.NET itself. I've changed the title to reflect this, but I'll leave the rest of the question text as-is until I find out more about the problem.
man,
i am with you in the same boat, i have spent like hours and hours trying to figure out what is the problem, and as you said it is a bug in both, as normal links that contain weird characters or UTF-8 code characters are parsed fine by asp.net.
i think we have to switch to MVC.routing
Update: man you wont believe it, i have found the problem it is so strange, it is with IIS,
try to launch your page from visual studio Dev server and Unicode characters will be parsed just fine, but if you launch the page from IIS 7 it will give you the ???? characters.
hope some body will shade some light here
I would have thought that %26 and '&' mean exactly the same thing to the web server, so its the expected behavior. Urlencode is for encoding URLs, not encoding query strings.
... hang on ...
Try searching for abc&def in google, you'll get:
http://www.google.com.au/search?q=abc%26def
So your query string is correct, %26 is a literal ampersand. Hmm you're right, sounds like a bug. How do you go with an & instead of the %26 ?
Interesting reading:
http://www.stylusstudio.com/xsllist/200104/post11060.html
Switching to UrlRewritingNet.UrlRewrite did not help, as it apparently has the same bug. I'm thinking it might have something to do with ASP.NET after all.
I think URLRewriter has a problem with nameless parameters (null name).
I had a similar problem. When I gave my nameless parameter a (dummy) name, everything worked as expected.