1

My question is about ASP.NET, VB.NET.

I have a website which is built in ASP.Net and Coding Part is VB.NET.

Now what is the problem - after the menus, to print something including a file and menus are placed inside a master controlled ".acsx" file.

The menu.acsx code is:

...menus links...
    <div>
    <%Response.WriteFile("~/Files/after_header.inc")%>
    </div>

Text written in "after_header.inc" is:

<p>Hello</p>

Now when I inspect the section below the menu and above the "Hello", it is displaying a character like this:

<div>
&#65279;<p>Hello</p>
</div>

My question is: why this character code here? If I remove the code to include the file, then there is no issue.

Can someone help me out - this character is an unprintable character and destroying the website look - it generates an extra line below the menu.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
Viny Goyal
  • 105
  • 1
  • 1
  • 7
  • Possibility: Edit you after_header.inc (with Notepad++ for example) and remove UTF-8 BOM :) – Arvo Dec 20 '18 at 13:06
  • opened file in Notepad++ and then select "Encoding" and "ASCII" - changed the file, still the same Issue. – Viny Goyal Dec 20 '18 at 13:10

1 Answers1

3

If you convert 65279 to hexadecimal you will find it is FEFF, which is the byte order mark (BOM) for UTF-16.

Writing a file to the page like that isn't really the ASP.NET way of doing things. Instead, you should put a control there:

<asp:Literal ID="someSensibleName" runat="server"></asp:Literal>

and in the code behind, perhaps in the page load event handler, you would populate that control:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    someSensibleName.Text = IO.File.ReadAllText(Server.MapPath("~/Files/after_header.inc"))

End Sub

The ReadAllText will remove the BOM (if present) for you.

Andrew Morton
  • 24,203
  • 9
  • 60
  • 84
  • I may try it - are you sure? The issue will be resolved? Because as you told it may be the issue of file encoding – Viny Goyal Dec 20 '18 at 13:15
  • I have another question - if I change this master control website will go down for 3-4 hours. when I made any changes in Master pages and Master controls and upload to the server why website goes down? – Viny Goyal Dec 20 '18 at 13:20
  • @VinyGoyal That is indeed another question, and should be asked as a new question, but that possibly means that the disk drive that the website is on is too slow (also check if it is nearly full) and so the (automatic) recompilation of the web site takes a long time. Also, see everything in [Asp.net website first start is very slow](https://stackoverflow.com/q/26260/1115360). – Andrew Morton Dec 20 '18 at 13:26
  • website space is not more than 100 MB and server's space is 100 GB, I am using shared hosting with windows unlimited plan; Since I cannnot ask another question till 90 minutes... can you please suggest me here – Viny Goyal Dec 20 '18 at 13:31
  • @VinyGoyal Please read the answers in the link I gave a few minutes ago: one of them is likely to tell you why it takes so long. – Andrew Morton Dec 20 '18 at 13:33
  • I read it - this is not a solution for me; let me clear my architecture, website has 4 master pages, some of the master controls and 5000+ child pages and I am not using any database even coding - website is just like a static made using asp dot net, vb and using its some of the features. One more thing, I did not created build of the website and not published it. I just add the child page and upload them to server using filezilla. So when I make any changes in Master page and upload it - website went down. I need solution it. because we now have more than 1M pageviews per month – Viny Goyal Dec 20 '18 at 13:36
  • @VinyGoyal From the page I linked to, I would say this one probably applies: [The initial slowness is a couple things](https://stackoverflow.com/a/26421/1115360). The solution to that is a faster computer. [Schedule automatic daily upload with FileZilla](https://stackoverflow.com/q/24945709/1115360) might be useful as you could use ~some~ program to upload the files in the middle of the night when not many people are using the site. – Andrew Morton Dec 20 '18 at 13:49
  • 1
    @VinyGoyal I'll just add, try to not read from the server like that. The page can't page cached properly since it needs to read the file every time. It's better if you would use a user control. Using .inc file is the old asp way. – the_lotus Dec 20 '18 at 19:13
  • then what is the another way? BTW, in files there is only a few links and AdSense ad code - files I am using so that any time I can edit the ad codes, if I direct change in the master control - website went down for 3 hours. – Viny Goyal Dec 20 '18 at 20:15