2 // System.Web.Handlers.AssemblyResourceLoader
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System
.Reflection
;
36 namespace System
.Web
.Handlers
{
37 [MonoTODO ("Should we cache stuff?")]
41 internal // since this is in the .config file, we need to support it, since we dont have versoned support.
43 class AssemblyResourceLoader
: IHttpHandler
{
45 internal static string GetResourceUrl (Type type
, string resourceName
)
47 return "WebResource.axd?assembly="
48 + HttpUtility
.UrlEncode (type
.Assembly
.GetName ().FullName
)
50 + HttpUtility
.UrlEncode (resourceName
);
54 [MonoTODO ("Substitution not implemented")]
55 void System
.Web
.IHttpHandler
.ProcessRequest (HttpContext context
)
58 string resourceName
= context
.Request
.QueryString
["resource"];
59 Assembly assembly
= Assembly
.Load (context
.Request
.QueryString
["assembly"]);
62 foreach (WebResourceAttribute wra
in assembly
.GetCustomAttributes (typeof (WebResourceAttribute
), false)) {
63 if (wra
.WebResource
== resourceName
) {
64 context
.Response
.ContentType
= wra
.ContentType
;
66 if (wra
.PerformSubstitution
)
67 throw new NotImplementedException ("Substitution not implemented");
76 Stream s
= assembly
.GetManifestResourceStream (resourceName
);
78 byte [] buf
= new byte [1024];
79 Stream output
= context
.Response
.OutputStream
;
82 c
= s
.Read (buf
, 0, 1024);
83 output
.Write (buf
, 0, c
);
88 bool System
.Web
.IHttpHandler
.IsReusable { get { return true; }
}