Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a metatag like this.

<meta id="seoDescription" name="description" runat="server" />


Now i am setting this metatag content from codebase.

C#
string sContent = "a&b";
      seoDescription.Content = sContent;



Issue happens is that when i view source of page i get a & amp; b instead of a&b
Why & is converting into html value of & like & amp;
Posted
Updated 14-Nov-14 6:09am
v2

1 solution

You're not supposed to have an & on its own in an HTML document; it has to be encoded as &amp;.

The value from your database is being correctly HTML-encoded. There's nothing to worry about. :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Nov-14 12:37pm    
5ed.
—SA
k@ran 14-Nov-14 13:10pm    
Still same issue. If i save value in db as A & amp; B. Still source looks like

<head><meta id="seoDescription" name="description" content="A&ampB" />

but i need value in following format

<head><meta id="seoDescription" name="description" content="A&B" />
Richard Deeming 14-Nov-14 13:12pm    
There isn't an issue.

Your HTML must be valid. You cannot have an & character on its own in a valid HTML document.

Any code which reads your page will automatically handle the encoded characters, and know that &amp; means &.
k@ran 14-Nov-14 13:15pm    
Is it possible to show value in format like A&B in content attribute of meta tag ? If i print this value in literal then it shows correct value without encoding.
Richard Deeming 14-Nov-14 13:18pm    
So you want to generate INVALID HTML markup?

You can't do that with the <meta runat="server" ... /> control. You'll have to use a literal control, and generate the INVALID HTML yourself.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900