I have this code in my codebehind...
protected void Page_Init(object sender, EventArgs e)
{
RegisterCssFile("http://example.com/default.aspx?type=fm&theme=fm");
}
private void RegisterCssFile(string path)
{
var css = new HtmlGenericControl("link");
css.Attributes.Add("href", path);
css.Attributes.Add("type", "text/css");
css.Attributes.Add("rel", "stylesheet");
Page.Header.Controls.Add(css);
}
This renders
<link href="http://example.com/default.aspx?type=fm&theme=fm" type="text/css" rel="stylesheet"></link>
... which, as you can see, is wrong.
Why is the ampersand (&) encoded and how can I fix it?
Actually, this is correct. Why do you think it's wrong? It should be sent by the browser as just &
after HTML un-escaping. Does something not work for you?