Strange characters output on asp.net mvc page - asp.net

Sometimes (randomly) my asp.net mvc application outputs page where single character is being replaced with weird question marks, as shown on image
This behavior is constant until data changes, and it does not disappear with page refresh. The whole page is in Georgian unicode. I am using asp.net mvc 3 with visual studio 2010 and iis express. This is also observed on published site to IIS 7.5. I have seen similar issues in asp.net webforms application too.
I have observed this behavior not only on db-provided data, but simple anchors, generated with html helper
TagBuilder addAnchor = new TagBuilder("a");
addAnchor.AddCssClass("add-item");
addAnchor.MergeAttribute("href", "#");
addAnchor.SetInnerText(SharedResources.Add); //resource item contains string დამატება
which output anchor "დამატ���ბა"
And this is not issue with page rendering on browser-side, as raw response already contains these symbols.
Update:
As it seems, disabling buffer output by setting Response.BufferOutput = false; removes weird characters from page. But I use Cassette for referencing bundles, and it cannot work with disabled buffer output - no scipts or stylesheets get referenced on page.
Has anyone of you had a similar problem? This is actually critical for me, as currently it affects data where that single character being damaged is the correct answer information of a multi-select test question.

I had the same bug. It is Cassette with a feature that rewrites the result HTML content (and needs BufferOutput set to true) to move referenced script and stylesheet tags to the top if needed.
See the IsHtmlRewritingEnabled option at http://getcassette.net/documentation/configuration.
When I turned off this feature, the bug has disappeared.
My observations:
It is appeared only with remote requests. Local requests are always ok.
The location of question marks is always constant for all clients, browsers and computers.
The location of question marks changes only after recompilation of the application.

I would imagine it's to do with character sets. I've had this issue when i've tried to display a character that isn't in a particular character set.
such as ’ or – (’ or –) in UTF-8 when the character hasn't been HTML encoded previously.

I too had output like this. In my case the source of error was within Views/web.config. An assembly was listed in pages/namespaces, which was not part of the referenced assemblies

Related

UTF-8 characters messed up HTML tags in JSP in Spring MVC

In Spring mvc while displaying UTF-8 characters, the jsp is getting messed up. While debugging found that the http response itself contains the jsp content with some missing HTML tags. The UTF-8 contents are coming fine but the page is breaking some where else. The issue is inconsistent. I mean the page breaks in different place in different time. But the UTF contents are fine. Tried with all workaround but no result.
Is there any problem in either spring side or container side?
Finally I found the reason. We had some problem with the custom security filter where it was trying to convert the String into byte arrays and it was getting overflow for these UTF-8 characters.

Uploading large amount of content in to a content component

I need to publish out a large XML file (~8MB = ~28,000 lines) from Tridion (2011 SP1 HR1) on to the web sever(s).
I have done this in the past with similar sized XML documents by uploading the XML file in to a Multimedia Component in Tridion and then having a simple Component Template to render the contents of the file at publish time. However, in the Tridion implementation in which I am working there is already a mechanism for publishing out content to the site using a very simple 'Code' Content (not Multimedia) Component which has a single plain text field for the 'code'.
The problem that I am having is that the browser becomes unresponsive/crashes when I try to paste such a large amount of content in to the 'Code' Component. Does anyone know of a way (either in the browser or in Tridion) to make this possible? I do have the option of adding a Component Template to process this as a Multimedia Component, but I would be reluctant to do this if I could get the existing mechanism working.
I have tried this in IE, Chrome and Firefox. I have also tried uploading this using WebDav without success too. We have already increased the HTTP Upload size on the server to 0.5GB to accommodate large binary files.
Thanks,
Jonathan
The first thing that comes to mind is the WCF size restrictions in the CoreService configuration.
These are set in the Web.Config of the CME, under (by default): C:\Program Files (x86)\Tridion\web\WebUI\WebRoot

ASP.NET - Check if a WebControl contains server blocks?

Is there a way in code to determine if a Web control contains server blocks (other than, for example, parsing out the file, grabbing the contents of the tag, and scanning for <% ... %>)?
My reason for wanting this is because I have a lot of old Web forms that were designed without any regard whatsoever to HTML conformance. The header control (which is included on every page but is inside the body tag) contains the link tag referencing the site's main stylesheet. As long as the page's head tag does not contain server blocks, I can programmatically insert the link tag into Page.Controls.OfType(Of HtmlHead).First(), then set the visibility of the "bad" link tag to false.
Again, this is all legacy stuff (it's in 3.5 now, but most was written in the .NET 1.1 days), so changing everything over to use a master page is something for which I simply do not have the time and budget. Regardless, it would be nice to see the pages come up with the stylesheet pre-loaded, rather than having the browser begin rendering with no styling, then applying the stylesheet once it reaches the reference to it in the body.
Seems like a silly work around but could you change the name of your CSS file so that when the legacy code goes to load, it can't find it?
Although Mufasa entered his response as a comment, this question has been sitting unresolved too long. Therefore, I will surmise that the only solution is his -- to wrap it in a try/catch black.

Removing the byte order mark on asp.net page

I'm really stuck. I'm working on an integration project where I'm creating a html fragment using ASP.NET. This fragment will be included as part of another site. The html fragment is created using a simple ASP.NET page with a minimal code behind file.
Te site that will include this html fragment is running PHP. The developer there is complaining that my code is sending the byte order mark as part of the html fragment and this is making his life difficult.
I'm using Visual Studio 2010 for development. I've saved the relevant aspx and aspx.cs files as UTF-8 without signature. However, this doesn't seem to have made a difference and now I'm pretty much out of ideas. The rest of the site is set to use UTF-8 as standard (defined in web.config).
Where should I be looking to alter the BOM behaviour for my aspx file?
If you save the file in Visual Studio I believe it will keep adding the BOM. You need to use a different editor to remove the marker such as NotePad++.
Actually in the advanced save as dialog in Visual Studio there is also an option to save UTF-8 without signature. Have you tried this?
It's confirmed in this question.
You can also use plain old NotePad to save with a different encoding.
Save As...Encoding DropDown.

Minify Html output of ASP.NET Application

What are the ways by which we can reduce the size of the HTML Response sent by an asp.net application?
I am using Controls which are not owned by me and it produces output with white spaces. I am interested in Minifying the entire HTML output of the page just like how google does (View source www.google.com) to improve the timing.
Is there any Utility classes available for ASP.NET which can do this stuff for me?
There is no need to do it at run time. Because it can be done at compile time.
Details: http://omari-o.blogspot.com/2009/09/aspnet-white-space-cleaning-with-no.html
Try HTTP module as described here: http://madskristensen.net/post/a-whitespace-removal-http-module-for-aspnet-20
For Microsoft .NET platform there is a library called the WebMarkupMin, which produces the minification of HTML code. For each ASP.NET framework has its own module:
ASP.NET Core - WebMarkupMin.Web. Implemented as an HTTP module, so it can work with any framework. Suitable for use in the ASP.NET Web Pages framework (Razor).
ASP.NET MVC - WebMarkupMin.Mvc
ASP.NET Web Forms - WebMarkupMin.WebForms
Documentation is available at - http://webmarkupmin.codeplex.com/documentation
I want to comment on Thorn's suggestion (but I'm new to stack overflow).
The linked code (omari-o.blogspot.com) doesn't support MVC4, and although the code is open source it cannot easily be upgraded because of braking changes between MVC3 and MVC4.
There might be whitespaces written to the http result at runtime, only the developer of the actual site can know that. Thus static minification of template files (aspx) is not foolproof at all. Dynamic minification, which is suggested by gius, should be used to guarantee that whitespaces are removed correctly, and unfortunately this will incur a runtime computation cost. If code dynamically writes spaces to the output, it will have to be removed dynamically.
The accepted answer does not work with MVC 4, so here is a similar lib that minifies at build-time https://github.com/jitbit/HtmlOptimizerMvc4
Just adding another option I do not see listed here, which is the one I was recommended using:
Html minifier command line tool
Usage:
here and here
There is an issue, however, with this tool: it leaves single line (//) comments, and it causes problems for Razor parsing, since a single line comment placed within a C# block like the following:
#{
...
...
// anything
...
}
will cause the minification output rest of the line, from this point on, to be ignored by the Razor parser, which will thus raise an error stating there it could not find the closing "}" for the block.
My workaround for this issue was to completely removing these comments from the output.
This way it works.
To do that, simply remove the RegexOptions.SingleLine from line 145:
htmlContents = Regex.Replace(htmlContents, #"//(.*?)\r?\n", ""/*, RegexOptions.Singleline*/);

Resources