forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRazorHandler.cs
More file actions
48 lines (40 loc) · 1.5 KB
/
RazorHandler.cs
File metadata and controls
48 lines (40 loc) · 1.5 KB
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
using System.Net;
using ServiceStack.Common.Web;
using ServiceStack.ServiceHost;
using ServiceStack.Text;
using ServiceStack.WebHost.Endpoints.Support;
namespace ServiceStack.Razor
{
public class RazorHandler : HttpHandlerBase
{
public RazorFormat RazorFormat { get; set; }
public ViewPageRef RazorPage { get; set; }
public string PathInfo { get; set; }
public string FilePath { get; set; }
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
httpRes.ContentType = ContentType.Html;
var contentPage = RazorPage;
if (contentPage == null)
{
var pageFilePath = this.FilePath.WithoutExtension();
contentPage = RazorFormat.GetContentPage(pageFilePath);
}
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
return;
}
if (RazorFormat.WatchForModifiedPages)
RazorFormat.ReloadModifiedPageAndTemplates(contentPage);
//Add extensible way to control caching
//if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
// return;
var modelType = RazorPage.GetRazorTemplate().ModelType;
var model = modelType == typeof(DynamicRequestObject)
? null
: DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
}
}
}