internal static PortalContextInitInfo CreateInitInfo(HttpContext context)
{
var requestUri = context.Request.Url;
var absPathLower = requestUri.AbsolutePath.ToLower();
// check basic auth headers
string authHeader = context.Request.Headers["Authorization"];
string basicAuthHeaders = null;
if (authHeader != null && authHeader.StartsWith("Basic "))
{
basicAuthHeaders = authHeader;
// remove header so that IIS will not send 401 automatically when remapping action to webdavhandler
context.Request.Headers.Remove("Authorization");
}
//---- STEP 1: Search for a matching Site URL based on the Request URL
string matchingSiteUrl = null;
// Drop the scheme (http://) and the querystring parts of the URL
// Example: htttp://localhost:1315/public/folder1? ==> localhost:1315/public/folder1
string nakedRequestUrl = requestUri.GetComponents(UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.Unescaped);
if (nakedRequestUrl.EndsWith(InRepositoryPageSuffix))
nakedRequestUrl = nakedRequestUrl.Remove(nakedRequestUrl.Length - InRepositoryPageSuffix.Length);
// Get the matching site url (if any)
Site requestedSite = null;
foreach (string siteUrl in Sites.Keys)
{
if (nakedRequestUrl.StartsWith(siteUrl) &&
(nakedRequestUrl.Length == siteUrl.Length || nakedRequestUrl[siteUrl.Length] == '/' || nakedRequestUrl[siteUrl.Length] == '?'))
{
matchingSiteUrl = siteUrl;
requestedSite = Sites[siteUrl];
break;
}
}
//---- STEP 2: WebDav
bool isWebdavRequest = false;
var translateHeader = context.Request.Headers["Translate"];
if (!string.IsNullOrEmpty(translateHeader))
translateHeader = translateHeader.ToLower();
var useragent = context.Request.Headers["User-Agent"];
var ualower = string.Empty;
if (!string.IsNullOrEmpty(useragent))
ualower = useragent.ToLower();
isWebdavRequest = ualower.Contains("webdav") || ualower.StartsWith("microsoft office") || ualower.Contains("frontpage") || translateHeader == "f";
if (isWebdavRequest && absPathLower.StartsWith(TrashBin.TrashBinPath.ToLower()))
{
EndResponse(404);
return null;
}
//---- STEP 3: Create Repository Path
string repositoryPath = null;
string siteRelativePath = null;
//---- if Webroot
if (PortalContext.WebRootFiles.Any(n => n == absPathLower))
{
repositoryPath = ContentRepository.Storage.RepositoryPath.Combine(PortalContext.WebRootFolderPath, absPathLower);
siteRelativePath = null;
}
var isOfficeProtocolRequest = false;
//---- if DWSS (Document Workspace Web Service Protocol)
if (absPathLower.EndsWith("_vti_bin/dws.asmx") ||
absPathLower.EndsWith("_vti_bin/webs.asmx") ||
absPathLower.EndsWith("_vti_bin/lists.asmx") ||
absPathLower.EndsWith("_vti_bin/versions.asmx") ||
absPathLower.EndsWith("_vti_bin/owssvr.dll"))
{
if (absPathLower.StartsWith(TrashBin.TrashBinPath.ToLower()))
{
EndResponse(404);
return null;
}
var requestPath = absPathLower;
var prefix = "_vti_bin";
var prefixIdx = requestPath.IndexOf(prefix);
var redirectPath = string.Concat(PortalContext.WebRootFolderPath, "/DWS", requestPath.Substring(prefixIdx + prefix.Length)); // ie. /Root/System/WebRoot/DWS/lists.asmx ...
repositoryPath = redirectPath.Replace("owssvr.dll", "owssvr.aspx");
isWebdavRequest = false; // user agent might be webdav, but we should redirect to given content, and not to webdav service
isOfficeProtocolRequest = true;
}
//---- if FPP (FrontPage Protocol)
if (absPathLower.EndsWith("_vti_inf.html") ||
absPathLower.EndsWith("_vti_rpc") ||
absPathLower.EndsWith("_vti_aut/author.dll") ||
absPathLower.EndsWith("_vti_bin/workflow.asmx"))
{
if (absPathLower.StartsWith(TrashBin.TrashBinPath.ToLower()))
{
EndResponse(404);
return null;
}
// NOTE: workflow.asmx is not actually implemented, we return a HTTP 200 using FppHandler.cs
repositoryPath = string.Concat(PortalContext.WebRootFolderPath, "/DWS/Fpp.ashx");
isWebdavRequest = false; // user agent might be webdav, but we should redirect to given content, and not to webdav service
isOfficeProtocolRequest = true;
}
// otherwise (not webroot, not fpp, not dws): set repositorypath to addressed repository content path
if (repositoryPath == null)
{
if (matchingSiteUrl != null)
{
//siteRelativePath = requestUri.AbsolutePath; //-- ez nem jo, mert nincs unescape (%20)
siteRelativePath = nakedRequestUrl.Substring(matchingSiteUrl.Length);
repositoryPath = StartsWithRoot(siteRelativePath) ? siteRelativePath : string.Concat(Sites[matchingSiteUrl].Path, siteRelativePath);
// Remove trailing slash
if (repositoryPath.EndsWith("/"))
repositoryPath = repositoryPath.Substring(0, repositoryPath.Length - 1);
}
else
{
// The request does not belong to a site (eg. "http://localhost/Root/System/Skins/Test.css")
repositoryPath = HttpUtility.UrlDecode(requestUri.AbsolutePath);
//TODO: check this
string appPath = context.Request.ApplicationPath;
if (appPath != null && appPath.Length > 1)
repositoryPath = repositoryPath.Substring(appPath.Length - 1);
}
}
//---- STEP 4: if Cassini
if (requestedSite != null && siteRelativePath == "/default.aspx")
{
repositoryPath = requestedSite.Path;
siteRelativePath = "";
}
//---- STEP 5: Appmodel elements: requested nodeHead, action, app, context
var requestedNodeHead = NodeHead.Get(repositoryPath);
var actionName = context.Request.Params[ActionParamName];
var appNodePath = context.Request.Params[AppNodeParamName];
var contextNodePath = context.Request.Params[ContextNodeParamName];
var versionRequest = context.Request.Params[VersionParamName];
AssertAppmodelelements(requestedNodeHead, actionName, appNodePath, contextNodePath);
//---- STEP 6: BinaryHandler requestednodehead for preliminary is-modified-since handling
NodeHead binaryhandlerRequestedNodeHead = null;
if (absPathLower.EndsWith("/binaryhandler.ashx") && String.IsNullOrEmpty(actionName))
binaryhandlerRequestedNodeHead = SenseNet.Portal.Handlers.BinaryHandler.RequestedNodeHead;
Site requestedNodeSite = null;
if (repositoryPath != null)
requestedNodeSite = Site.GetSiteByNodePath(repositoryPath);
return new PortalContextInitInfo()
{
RequestUri = requestUri,
IsWebdavRequest = isWebdavRequest,
IsOfficeProtocolRequest = isOfficeProtocolRequest,
BasicAuthHeaders = basicAuthHeaders,
RequestedSite = requestedSite,
SiteUrl = matchingSiteUrl,
SiteRelativePath = siteRelativePath,
RepositoryPath = repositoryPath,
RequestedNodeHead = requestedNodeHead,
ActionName = actionName,
AppNodePath = appNodePath,
ContextNodePath = contextNodePath,
VersionRequest = versionRequest,
BinaryHandlerRequestedNodeHead = binaryhandlerRequestedNodeHead,
DeviceName = PortalContext.GetRequestedDevice(),
RequestedNodeSite = requestedNodeSite
};
}
internal static PortalContext Create(HttpContext context)