Search code examples
.netasp.netembedded-resource

Trying to retrieve an embedded resource in asp.net


I am trying to retrieve the ResourceStyle.css embedded resource by using the Page.ClientScript.GetWebResourceUrl() method. However, I receive a 404 resource not found error when I try to browse to the url that GetWebResourceUrl() returns.

I have already set the build action for ResourceStyle.css to Embedded Resource and added the [assembly: WebResource()] attribute in the Default.aspx.cs file.

I have uploaded the project to github. If you know how to resolve this issue, please fork the repository and make the necessary changes and then send me a pull request. Look at the Default.aspx.cs file for the pertinent code.


Solution

  • GetWebResourceUrl() requires two arguments, a type and the name of the embedded resource. I was using this.GetType() as the first argument, but GetType() doesn't work if the class uses inheritance. I used typeof() instead of now it works.

    Page.ClientScript.GetWebResourceUrl(typeof(_Default), "WebResources.Styles.ResourceStyle.css");