Removing the byte order mark on asp.net page - asp.net

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.

Related

ASP vs Inc behavior difference with html.encode

For my current project i work with include files (.inc) inside visual studio.
What i did is changed some inc files to asp.
But when i consult my page i have a strange behavior with special characters.
Examples
André for André
Priv� for privé
When i use html.encode i do not get any good result.
In versioncontrol i noticed the only thing that's changed are the extentions for the include files.
Is this normal behavior ?
What did i mis or do wrong ?
I found the cuase of my problem.
In visual studio each file i create is in UTF-8 encoding.
What i need to do is change the encoding from UTF-8 to ANSI.
Problem solved.
In vs-2019, you can save a file with encoding:
From the File menu, choose Save File As, and then click the drop-down button next to the Save button.
The Advanced Save Options dialog box is displayed.
Under Encoding, select the encoding to use for the file.
[https://learn.microsoft.com/en-us/visualstudio/ide/how-to-save-and-open-files-with-encoding?view=vs-2019#to-save-a-file-with-encoding][1]

Strange characters output on asp.net mvc page

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

Automatically generate resource keys for localisation in Visual Studio

I have a large website that I have to localise. To do that, I make use of UI cultures and .resx files. But the controls on the site do not have the meta:resourcekey value necessary to refer to them in the resource files. I'd like to generate them automatically, using the element IDs as the keys, so that this:
<ext:Window ID="wndLoginWindow" Hidden="true">
</ext:Window>
Becomes this:
<ext:Window ID="wndLoginWindow" Hidden="true" meta:resourcekey="wndLoginWindow">
</ext:Window>
Is there a Visual Studio tool/plugin to do this? Do I have to resort to regex substitution? Or is there another way to localise the website that's not as manual to implement?
Visual Studio 2010 has a Generate Local Resource option under the Tools menu. The cursor may have to be actively in the content area for the menu option to be available. I've been using this to create resource files and it automatically adds the resource key attribute to my controls. It works with Literals and Labels and the like but might not work for more complex controls (my pages are pretty simple so I haven't run up against that).

Regenerate designer.cs [duplicate]

This question already has answers here:
How do you force Visual Studio to regenerate the .designer files for aspx/ascx files?
(48 answers)
Closed 9 years ago.
I just deleted a designer.cs file from a aspx page.. (Don't ask how I can do that.. You don't really want to know..)
Is it a way to regenerate the file for the aspx page? I was hoping that something like "right-click/ generate designer" exists but it is not the case.. :-(
So thanks if somebody have an idea..
Find another solution to my Question, right-click on the aspx file, then choose "convert to web application" and then, the designer.cs file is regenerated..
It is more easier and quick..
This option is no longer available in VS2013, but you can accomplish the same thing by selecting your project in the Solution Explorer, then going to the Project option on the Menu Bar. Near the bottom you will see the Convert to Web Application option. This will generate designer files for all the *.aspx pages in your project that don't have them, but be aware that this may not be what you want if you have a mix of CodeFile *.aspx pages and CodeBehind files. This will also convert CodeFile pages to CodeBehind files. (Courtesy Joisey Mike)
Open the designer and save (you might have to change something in the markup before being able to save). It should be recreated. Event subscriptions and other settings only kept in the designer won't be possible restore though.
EDIT: Make sure that the designer file exists by creating an empty file with just the partial class definition. Also make sure that it's registered in the project file. Then open the designer or the aspx page and make one small change (insert a space in the aspx) and save it. Now the designer file should be recreated.
Use R-Studio from http://www.r-tt.com and undelete it. Use Source Control in the future.
Part from that, try copying the GUI controls into a new page and copy the content of its Designer page to your deleted one.
If editing and saving your aspx file doesn't work, try the following:
Restart Visual Studio
Ensure there are no errors in your aspx file (e.g. missing <%# Register ... %> tags)
Having ReSharper installed helps with step 2 as it prompts to automatically register missing user controls (but in my case, only after a restart).
This worked for me in Visual Studio 2008.
View in browser should recreate it.
Along with all the other suggestions:
In my case, it was a user control that began missing it's designer file. So, in the ascx, I commented out all the content, leaving only the Assembly,Register, and Import headers. I then rebuilt the solution. With that success, I had new designer code auto generated. I removed the comments and rebuilt again. Everything was back in the place it should be.
Your mileage may vary.
Edit: It should be able to recreate it somehow. However my tip still stands: use source control. Some time in the future, you will delete something vital and can't restore it via any means, and then you will be grateful for having source control.

Asp.net how to convert HTML page to PDF

I have read all the related links to this question but nothing show what i want :(
so i am asking :
Now i have a HTML page and i need to make a link or button to convert this page to pdf
so is there any FREE dll that i pass the HTML to it and it returns a PDF.
hint: i am using vs2010, MVC3.0, c#4.0
Personally I am using the following Java library where I compiled the .jar into a .NET assembly using the IKVM.NET Bytecode Compiler.

Resources