WebResourceAttribute fails validation

Last post 02-11-2008 3:27 AM by auband. 3 replies.

Sort Posts:

  • WebResourceAttribute fails validation

    02-06-2008, 3:14 AM
    • Loading...
    • auband
    • Joined on 05-03-2007, 7:48 AM
    • Norway
    • Posts 47

     

    Hi all

    I’m including some css files in my web app using WebResourceAttribute.
     

    [assembly: WebResource("MyWebApp.Custom.Controls.CSS.MessageBox.css", "text/css")]
    namespace MyWebApp.Custom.Controls
    {
    public class MessageBox : WebControl, INamingContainer
    {

    ...

    public void RegisterStyleSheet(Page page)
    {
    string csslink = "<link href='" + page.ClientScript.GetWebResourceUrl(this.GetType(),
    "MyWebApp.Custom.Controls.CSS.MessageBox.css") +
    "' rel='stylesheet' type='text/css' />";

    LiteralControl include = new LiteralControl(csslink);
    page.Header.Controls.Add(include);
    }

    ...
      


    This generates this kind of html

     

    <head>
    ...
    <link href='/WebResource.axd?d=vVjymapQ8NgnF9dPwwk1nBHNmC71e9xXdBXLBsak7ZafMvPwpjMgr9vZFjnsTvZVaOTpt0K8iwEmECwLrNcIdg2&t=633378841003442963' rel='stylesheet' type='text/css' />
    ...
    </head>
      

    The thing is the cryptic string fails the markup validation at w3.org. I’m getting errors and warnings, pointing to parts of the string (the & and the = in particular), like:

    Warning: cannot generate system identifier for general entity "t". 

    Error: general entity "t" not defined and no default entity. 

    Warning: reference not terminated by REFC delimiter.

    Warning: reference to external entity in attribute value.

    Error: reference to entity "t" for which no system identifier could be generated. 

     

    Anyone know a workaround to this?

    Thanks for any input! 

    -Andreas Aubell-
  • Re: WebResourceAttribute fails validation

    02-10-2008, 10:32 PM

    auband:
    The thing is the cryptic string fails the markup validation at w3.org. I’m getting errors and warnings, pointing to parts of the string (the & and the = in particular), like:
     

    Hi auband,

    Base on my experience, replace "&" by "&amp;" might solve your problem.

    Let me know if I have misunderstood what you mean. Thanks.

    Hope it helps,

    Hong Gang 


     

    Sincerely,
    Hong-Gang Chen
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: WebResourceAttribute fails validation

    02-10-2008, 10:46 PM

    Another thing you might want to do is use ResolveClientUrl method with the url and prefixing it with "~"

    So it would be

    string csslink = "<link href='" + ResolveClientUrl("~" + page.ClientScript.GetWebResourceUrl(this.GetType(),
                                 "MyWebApp.Custom.Controls.CSS.MessageBox.css")) +
                                 "' rel='stylesheet' type='text/css' />";

  • Re: WebResourceAttribute fails validation

    02-11-2008, 3:27 AM
    Answer
    • Loading...
    • auband
    • Joined on 05-03-2007, 7:48 AM
    • Norway
    • Posts 47

    Hong Gang Chen: the string is a pointer to a resource and should probably not be tampered with in order to retrieve the resource when needed.

     
    Rob Mills: I tried your suggestion but it made no difference.
     

    But, the good news is reading this article http://support.microsoft.com/kb/910442 (witch also explains WebResources in general) a bit closer gave me a solution
      

    string cssHref = page.ClientScript.GetWebResourceUrl(this.GetType(), "MyWebApp.Custom.Controls.CSS.MessageBox.css");

    HtmlLink link = new HtmlLink();
    link.Href = cssHref;
    link.ID = Guid.NewGuid().ToString();
    link.Attributes.Add("type", "text/css");
    link.Attributes.Add("rel", "stylesheet");

    page.Header.Controls.Add(link);

     

    Thanks to both of you anyway
     

    -Andreas Aubell-
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter