-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathAppHostBase.cs
More file actions
84 lines (73 loc) · 2.51 KB
/
AppHostBase.cs
File metadata and controls
84 lines (73 loc) · 2.51 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#if !NETCORE
using System;
using System.Reflection;
using System.Web;
using ServiceStack.Host;
using ServiceStack.Host.AspNet;
using ServiceStack.Web;
namespace ServiceStack
{
/// <summary>
/// Inherit from this class if you want to host your web services inside an
/// ASP.NET application.
/// </summary>
public abstract class AppHostBase : ServiceStackHost
{
protected AppHostBase(string serviceName, params Assembly[] assembliesWithServices)
: base(serviceName, assembliesWithServices)
{
#if !NET472
CookiesExtensions.Init();
#endif
}
public override string ResolveAbsoluteUrl(string virtualPath, IRequest httpReq)
{
if (httpReq == null)
return (Config.WebHostUrl ?? "/").CombineWith(virtualPath.TrimStart('~'));
virtualPath = virtualPath.SanitizedVirtualPath();
return httpReq.GetAbsoluteUrl(virtualPath);
}
public override string ResolvePhysicalPath(string virtualPath, IRequest httpReq)
{
var path = ((AspNetRequest)httpReq).HttpRequest.PhysicalPath;
return path;
}
public override IRequest TryGetCurrentRequest()
{
try
{
return HasStarted ? HttpContext.Current.ToRequest() : null;
}
catch
{
return null;
}
}
public override string MapProjectPath(string relativePath)
{
return relativePath.MapHostAbsolutePath();
}
public override string GetBaseUrl(IRequest httpReq)
{
var useHttps = UseHttps(httpReq);
var baseUrl = Config.WebHostUrl;
if (baseUrl != null)
return baseUrl.NormalizeScheme(useHttps);
var handlerPath = Config.HandlerFactoryPath;
baseUrl = httpReq.AbsoluteUri.InferBaseUrl(fromPathInfo: httpReq.PathInfo);
if (baseUrl != null)
{
if (handlerPath == null || baseUrl.EndsWith(handlerPath))
return baseUrl.NormalizeScheme(useHttps);
}
var aspReq = (HttpRequestBase)httpReq.OriginalRequest;
baseUrl = aspReq.Url.Scheme + "://" + aspReq.Url.Authority +
aspReq.ApplicationPath?.TrimEnd('/') + "/";
return baseUrl
.NormalizeScheme(useHttps)
.CombineWith(handlerPath)
.TrimEnd('/');
}
}
}
#endif