0

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?

Lee Francis
  • 547
  • 6
  • 15
  • 1
    You don't say how the html fragment is being saved and transmitted to the php site. tHe way your aspx files are saved has nothing to do with that, if you are creating these fragments within your code. – Andrew Barber Sep 18 '11 at 14:24
  • My fragment is saved in a aspx file and served as normal html so anyone can access it from a browser (but it's not valid html). The php site is importing this content on the backend and injecting the fragment in to it's own rendered output stream. Although I'm not doing the import work I'm pretty sure that this is just a normal HTTP call to my server. – Lee Francis Sep 19 '11 at 06:09

2 Answers2

2

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.

Community
  • 1
  • 1
TheCodeKing
  • 19,064
  • 3
  • 47
  • 70
  • As I mentioned, I'm saving as UTF-8 without the signature in Visual Studio 2010. I'm using the advanced save option to do this. – Lee Francis Sep 19 '11 at 06:10
  • I noticed notepad++ doesn't recognise the encoding from visual studio, what happens if you use a diff editor? Also how are you serving the file, you need to change the fragment and any files such as ASPX that it's served via. – TheCodeKing Sep 19 '11 at 06:22
  • Actually I noticed that neither Visual Studio 2010 or Notepad++ seems to recognize the files as anything other than ANSI once saved as UTF-8 without signature. I'm thinking this is a bug? The ASPX file is accessed directly from the web server. The code behind files are also saved as UTF-8 without signature. – Lee Francis Sep 19 '11 at 06:47
  • Think it might be, if I save the file without BOM in notepad++ and then again in VS (without sig) then it works. If I save without BOM first in VS, then notepad++ doesn't recognize the encoding. – TheCodeKing Sep 19 '11 at 08:16
0

You can also use plain old NotePad to save with a different encoding.

Save As...Encoding DropDown.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69
  • I'm pretty sure that I've configured Visual Studio 2010 to correctly save the files as UTF-8 without signature. – Lee Francis Sep 19 '11 at 06:12