-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDojoResourceHandler.cs
58 lines (49 loc) · 1.72 KB
/
DojoResourceHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
namespace Dojo.Net
{
public class DojoResourceHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string resourceName = "Dojo.Net.Resources" + context.Request.Url.AbsolutePath.Substring(context.Request.Url.AbsolutePath.IndexOf("/dojo.axd") + 9).Replace("/", ".");
Stream resourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
if (resourceStream == null)
{
context.Response.StatusCode = 404;
return;
}
switch (resourceName.Substring(resourceName.LastIndexOf(".") + 1))
{
case "js":
context.Response.ContentType = "application/x-javascript";
break;
case "css":
context.Response.ContentType = "text/css";
break;
case "png":
context.Response.ContentType = "image/png";
break;
case "gif":
context.Response.ContentType = "image/gif";
break;
}
byte[] buffer = new byte[102400];
int bytesRead = 0;
while ((bytesRead = resourceStream.Read(buffer, 0, buffer.Length)) > 0)
context.Response.OutputStream.Write(buffer, 0, bytesRead);
}
public bool IsReusable
{
get
{
return true;
}
}
}
}