Home Dashboard Directory Help
Search

Asp .Net Page Title Property Applies HtmlDecode Rather than HtmlEncode by Ben48


Status: 

Closed


2
0
Sign in
to vote
Type: Bug
ID: 778888
Opened: 2/9/2013 10:34:09 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Note this text is being encoded somehow which is making it very difficult for me to write what I want since it has to do with html encoding. If you are viewing the text below in a browser it doesn't really make sense - you need to click on details to see what I mean.


When I try and specify the title of my asp .net page via the Title property in the @Page directive (the page has a master page defined), whatever I enter as the title is html-decoded rather than html-encoded. For example
<%@ Page Title="X & Y" ..
produces
<title>X & Y</title>
I've had to resort to double encoding it as follows
<%@ Page Title="X & Y" ..
produces
<title>X & Y</title>
Details
Sign in to post a comment.
Posted by Ben48 on 2/12/2013 at 12:21 PM
But surely this can't be the intended behaviour? It doesn't really make any sense. If you set any html attribute in other server controls on an asp .net page, the behaviour is that the corresponding property gets assigned the value of whatever you have written, then when the control is rendered it is encoded as html. But in the case of the page title it seems to be almost the opposite. For some reason, when you specify if page title in the @Page directive it seems to be html decoded even though if you specify it in code it is not html decoded. Then no html encoding is applied when the title is automatically written to the page even though it is clearly required.
I don't think changing this would be a large break in behaviour. There are a few different cases. The most common one is that a page title contains no special characters so nothing changes there. The second is that someone is specifying a page title which is being automatically inserted in an empty <title></title> element in the master page when the page is rendered and the title contains special characters. This is what I was trying to do. Anyone doing it this way would either not have noticed that there was no encoding (so their html is invalid and updating the behaviour would fix their html) or they would like me have tried to encode it, then realised than it was being decoded, then either tried double encoding (which is clearly a dodgy solution anyway) or done it some other way like the next way I'm describing. Thirdly, they could be doing it your way, ie explicitly writing out and encoding the title in the master page. In this case since the title element is not empty there is no need for automatic generation of the title with html encoding. Also perhaps you have a system for preventing double html encoding? There are probably a few other scenarios, but if the change was applied only to the current/next version of the framework then I don't really see that it would be a big issue.
It seems like you have noticed this issue and have introduced a workaround as standard practice in the new templates but I think it would be better to fix the problem.

Thanks
Posted by Microsoft on 2/11/2013 at 3:48 PM
Changing this behavior would unfortunately be a break in behavior and as such is very difficult for us to change in a future update. Take a look at how the Visual Studio 2012 default project templates set the page title in their Master Page to get around this issue.
Posted by Microsoft on 2/10/2013 at 9:37 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 2/9/2013 at 10:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.