本文整理汇总了C#中IHttpRequest.GetPathUrl方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.GetPathUrl方法的具体用法?C# IHttpRequest.GetPathUrl怎么用?C# IHttpRequest.GetPathUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpRequest
的用法示例。
在下文中一共展示了IHttpRequest.GetPathUrl方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
var fileName = request.GetPhysicalPath();
var fi = new FileInfo(fileName);
if (!fi.Exists)
{
if ((fi.Attributes & FileAttributes.Directory) != 0)
{
foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
{
var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
if (!File.Exists(defaultFileName)) continue;
response.Redirect(request.GetPathUrl() + '/' + defaultDoc);
return;
}
}
if (!fi.Exists)
throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
}
TimeSpan maxAge;
if (response.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(response.ContentType, out maxAge))
{
response.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
}
if (request.HasNotModifiedSince(fi.LastWriteTime))
{
response.ContentType = MimeTypes.GetMimeType(fileName);
response.StatusCode = 304;
return;
}
try
{
response.AddHeaderLastModified(fi.LastWriteTime);
response.ContentType = MimeTypes.GetMimeType(fileName);
if (!Env.IsMono)
{
response.TransmitFile(fileName);
}
else
{
response.WriteFile(fileName);
}
}
catch (Exception)
{
throw new HttpException(403, "Forbidden.");
}
}
示例2: Execute
public void Execute(IHttpRequest httpReq, IHttpResponse httpRes)
{
httpRes.ContentType = "text/xml";
var baseUri = httpReq.AbsoluteUri; // .GetParentBaseUrl();
var optimizeForFlash = httpReq.QueryString["flash"] != null;
var includeAllTypesInAssembly = httpReq.QueryString["includeAllTypes"] != null;
var operations = includeAllTypesInAssembly ? EndpointHost.AllServiceOperations : EndpointHost.ServiceOperations;
var wsdlTemplate = GetWsdlTemplate(operations, baseUri, optimizeForFlash, includeAllTypesInAssembly, httpReq.GetPathUrl());
httpRes.Write(wsdlTemplate.ToString());
}
示例3: ReturnRequestInfo
private static IHttpHandler ReturnRequestInfo(IHttpRequest httpReq)
{
if (EndpointHost.Config.DebugOnlyReturnRequestInfo
|| (EndpointHost.DebugMode && httpReq.PathInfo.EndsWith("__requestinfo")))
{
var reqInfo = RequestInfoHandler.GetRequestInfo(httpReq);
reqInfo.Host = EndpointHost.Config.DebugHttpListenerHostEnvironment + "_v" + Env.ServiceStackVersion + "_" + EndpointHost.Config.ServiceName;
reqInfo.PathInfo = httpReq.PathInfo;
reqInfo.Path = httpReq.GetPathUrl();
return new RequestInfoHandler { RequestInfo = reqInfo };
}
return null;
}
示例4: GetHandler
// Entry point for HttpListener
public static IHttpHandler GetHandler(IHttpRequest httpReq)
{
foreach (var rawHttpHandler in RawHttpHandlers)
{
var reqInfo = rawHttpHandler(httpReq);
if (reqInfo != null) return reqInfo;
}
var mode = EndpointHost.Config.ServiceStackHandlerFactoryPath;
var pathInfo = httpReq.PathInfo;
//Default Request /
if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/")
{
if (ApplicationBaseUrl == null)
SetApplicationBaseUrl(httpReq.GetPathUrl());
//e.g. CatchAllHandler to Process Markdown files
var catchAllHandler = GetCatchAllHandlerIfAny(httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath());
if (catchAllHandler != null) return catchAllHandler;
return ServeDefaultHandler ? DefaultHttpHandler : NonRootModeDefaultHttpHandler;
}
if (mode != null && pathInfo.EndsWith(mode))
{
var requestPath = pathInfo;
if (requestPath == "/" + mode
|| requestPath == mode
|| requestPath == mode + "/")
{
//TODO: write test for this
if (httpReq.GetPhysicalPath() != WebHostPhysicalPath
|| !File.Exists(Path.Combine(httpReq.ApplicationFilePath, DefaultRootFileName ?? "")))
{
return new IndexPageHttpHandler();
}
}
var okToServe = ShouldAllow(httpReq.GetPhysicalPath());
return okToServe ? DefaultHttpHandler : ForbiddenHttpHandler;
}
return GetHandlerForPathInfo(httpReq.HttpMethod, pathInfo, pathInfo, httpReq.GetPhysicalPath())
?? NotFoundHttpHandler;
}
示例5: ReturnRequestInfo
internal static IHttpHandler ReturnRequestInfo(IHttpRequest httpReq)
{
if ((HostContext.DebugMode
|| HostContext.Config.AdminAuthSecret != null)
&& httpReq.QueryString[Keywords.Debug] == Keywords.RequestInfo)
{
if (HostContext.DebugMode || HostContext.HasValidAuthSecret(httpReq))
{
var reqInfo = RequestInfoHandler.GetRequestInfo(httpReq);
reqInfo.Host = HostContext.Config.DebugHttpListenerHostEnvironment + "_v" + Env.ServiceStackVersion + "_" + HostContext.ServiceName;
reqInfo.PathInfo = httpReq.PathInfo;
reqInfo.GetPathUrl = httpReq.GetPathUrl();
return new RequestInfoHandler { RequestInfo = reqInfo };
}
}
return null;
}
示例6: GetHandler
// Entry point for HttpListener
public static IHttpHandler GetHandler(IHttpRequest httpReq)
{
var appHost = HostContext.AppHost;
foreach (var rawHttpHandler in appHost.RawHttpHandlers)
{
var reqInfo = rawHttpHandler(httpReq);
if (reqInfo != null) return reqInfo;
}
var mode = appHost.Config.HandlerFactoryPath;
var pathInfo = httpReq.PathInfo;
//Default Request /
if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/")
{
//If the fallback route can handle it, let it
if (appHost.Config.FallbackRestPath != null)
{
string contentType;
var sanitizedPath = RestHandler.GetSanitizedPathInfo(pathInfo, out contentType);
var restPath = appHost.Config.FallbackRestPath(httpReq.HttpMethod, sanitizedPath, httpReq.GetPhysicalPath());
if (restPath != null)
{
return new RestHandler { RestPath = restPath, RequestName = restPath.RequestType.GetOperationName(), ResponseContentType = contentType };
}
}
SetApplicationBaseUrl(httpReq.GetPathUrl());
//e.g. CatchAllHandler to Process Markdown files
var catchAllHandler = GetCatchAllHandlerIfAny(httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath());
if (catchAllHandler != null) return catchAllHandler;
if (mode == null)
return DefaultHttpHandler;
if (DefaultRootFileName != null)
return StaticFilesHandler;
return NonRootModeDefaultHttpHandler;
}
if (mode != null && pathInfo.EndsWith("/" + mode))
{
return ReturnDefaultHandler(httpReq);
}
return GetHandlerForPathInfo(httpReq.HttpMethod, pathInfo, pathInfo, httpReq.GetPhysicalPath())
?? NotFoundHttpHandler;
}
示例7: ReturnRequestInfo
private IHttpHandler ReturnRequestInfo(IHttpRequest httpReq)
{
if (_endpointHost.Config.DebugOnlyReturnRequestInfo)
{
var reqInfo = RequestInfoHandler.GetRequestInfo(httpReq);
reqInfo.Host = _endpointHost.Config.DebugHttpListenerHostEnvironment + "_v" + Env.ServiceStackVersion + "_" + _endpointHost.Config.ServiceName;
reqInfo.PathInfo = httpReq.PathInfo;
reqInfo.Path = httpReq.GetPathUrl();
return new RequestInfoHandler { RequestInfo = reqInfo };
}
return null;
}
示例8: GetHandler
// Entry point for HttpListener
public static IHttpHandler GetHandler(IHttpRequest httpReq)
{
var appHost = HostContext.AppHost;
foreach (var rawHttpHandler in appHost.RawHttpHandlers)
{
var reqInfo = rawHttpHandler(httpReq);
if (reqInfo != null) return reqInfo;
}
var mode = appHost.Config.ServiceStackHandlerFactoryPath;
var pathInfo = httpReq.PathInfo;
//Default Request /
if (string.IsNullOrEmpty(pathInfo) || pathInfo == "/")
{
if (ApplicationBaseUrl == null)
SetApplicationBaseUrl(httpReq.GetPathUrl());
//e.g. CatchAllHandler to Process Markdown files
var catchAllHandler = GetCatchAllHandlerIfAny(httpReq.HttpMethod, pathInfo, httpReq.GetPhysicalPath());
if (catchAllHandler != null) return catchAllHandler;
if (mode == null)
return DefaultHttpHandler;
if (DefaultRootFileName != null)
return StaticFileHandler;
return NonRootModeDefaultHttpHandler;
}
if (mode != null && pathInfo.EndsWith(mode))
{
var requestPath = pathInfo;
if (requestPath == "/" + mode
|| requestPath == mode
|| requestPath == mode + "/")
{
var pathProvider = HostContext.VirtualPathProvider;
var defaultDoc = pathProvider.GetFile(DefaultRootFileName ?? "");
if (httpReq.GetPhysicalPath() != WebHostPhysicalPath
|| defaultDoc == null)
{
return new IndexPageHttpHandler();
}
}
var okToServe = ShouldAllow(httpReq.GetPhysicalPath());
return okToServe ? DefaultHttpHandler : ForbiddenHttpHandler;
}
return GetHandlerForPathInfo(httpReq.HttpMethod, pathInfo, pathInfo, httpReq.GetPhysicalPath())
?? NotFoundHttpHandler;
}
示例9: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.EndHttpRequest(skipClose: true, afterBody: r => {
var fileName = request.GetPhysicalPath();
var fi = new FileInfo(fileName);
if (!fi.Exists)
{
if ((fi.Attributes & FileAttributes.Directory) != 0)
{
foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
{
var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
if (!File.Exists(defaultFileName)) continue;
r.Redirect(request.GetPathUrl() + '/' + defaultDoc);
return;
}
}
if (!fi.Exists)
{
var originalFileName = fileName;
if (Env.IsMono)
{
//Create a case-insensitive file index of all host files
if (allFiles == null)
allFiles = CreateFileIndex(request.ApplicationFilePath);
if (allDirs == null)
allDirs = CreateDirIndex(request.ApplicationFilePath);
if (allFiles.TryGetValue(fileName.ToLower(), out fileName))
{
fi = new FileInfo(fileName);
}
}
if (!fi.Exists)
{
var msg = "Static File '" + request.PathInfo + "' not found.";
log.WarnFormat("{0} in path: {1}", msg, originalFileName);
throw new HttpException(404, msg);
}
}
}
TimeSpan maxAge;
if (r.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(r.ContentType, out maxAge))
{
r.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
}
if (request.HasNotModifiedSince(fi.LastWriteTime))
{
r.ContentType = MimeTypes.GetMimeType(fileName);
r.StatusCode = 304;
return;
}
try
{
r.AddHeaderLastModified(fi.LastWriteTime);
r.ContentType = MimeTypes.GetMimeType(fileName);
if (fileName.EqualsIgnoreCase(this.DefaultFilePath))
{
if (fi.LastWriteTime > this.DefaultFileModified)
SetDefaultFile(this.DefaultFilePath); //reload
r.OutputStream.Write(this.DefaultFileContents, 0, this.DefaultFileContents.Length);
r.Close();
return;
}
if (!Env.IsMono)
{
r.TransmitFile(fileName);
}
else
{
r.WriteFile(fileName);
}
}
catch (Exception ex)
{
log.ErrorFormat("Static file {0} forbidden: {1}", request.PathInfo, ex.Message);
throw new HttpException(403, "Forbidden.");
}
});
}
示例10: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.EndHttpHandlerRequest(skipClose: true, afterBody: r => {
var fileName = request.GetPhysicalPath();
var fi = new FileInfo(fileName);
if (!fi.Exists)
{
if ((fi.Attributes & FileAttributes.Directory) != 0)
{
foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
{
var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
if (!File.Exists(defaultFileName)) continue;
r.Redirect(request.GetPathUrl() + '/' + defaultDoc);
return;
}
}
if (!fi.Exists)
{
var originalFileName = fileName;
if (Env.IsMono)
{
//Create a case-insensitive file index of all host files
if (allFiles == null)
allFiles = CreateFileIndex(request.ApplicationFilePath);
if (allDirs == null)
allDirs = CreateDirIndex(request.ApplicationFilePath);
if (allFiles.TryGetValue(fileName.ToLower(), out fileName))
{
fi = new FileInfo(fileName);
}
}
if (!fi.Exists)
{
var msg = "Static File '" + request.PathInfo + "' not found.";
log.WarnFormat("{0} in path: {1}", msg, originalFileName);
throw new HttpException(404, msg);
}
}
}
TimeSpan maxAge;
if (r.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(r.ContentType, out maxAge))
{
r.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
}
if (request.HasNotModifiedSince(fi.LastWriteTime))
{
r.ContentType = MimeTypes.GetMimeType(fileName);
r.StatusCode = 304;
return;
}
try
{
r.AddHeaderLastModified(fi.LastWriteTime);
r.ContentType = MimeTypes.GetMimeType(fileName);
if (fileName.EqualsIgnoreCase(this.DefaultFilePath))
{
if (fi.LastWriteTime > this.DefaultFileModified)
SetDefaultFile(this.DefaultFilePath); //reload
r.OutputStream.Write(this.DefaultFileContents, 0, this.DefaultFileContents.Length);
r.Close();
return;
}
if (EndpointHost.Config.AllowPartialResponses)
r.AddHeader(HttpHeaders.AcceptRanges, "bytes");
long contentLength = fi.Length;
long rangeStart, rangeEnd;
var rangeHeader = request.Headers[HttpHeaders.Range];
if (EndpointHost.Config.AllowPartialResponses && rangeHeader != null)
{
rangeHeader.ExtractHttpRanges(contentLength, out rangeStart, out rangeEnd);
if (rangeEnd > contentLength - 1)
rangeEnd = contentLength - 1;
r.AddHttpRangeResponseHeaders(rangeStart: rangeStart, rangeEnd: rangeEnd, contentLength: contentLength);
}
else
{
rangeStart = 0;
rangeEnd = contentLength - 1;
r.SetContentLength(contentLength); //throws with ASP.NET webdev server non-IIS pipelined mode
}
var outputStream = r.OutputStream;
using (var fs = fi.OpenRead())
{
if (rangeStart != 0 || rangeEnd != fi.Length - 1)
{
fs.WritePartialTo(outputStream, rangeStart, rangeEnd);
//.........这里部分代码省略.........
示例11: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
var fileName = request.GetPhysicalPath();
var fi = new FileInfo(fileName);
if (!fi.Exists)
{
if ((fi.Attributes & FileAttributes.Directory) != 0)
{
foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
{
var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
var defaultFileInfo = new FileInfo(defaultFileName);
if (!defaultFileInfo.Exists) continue;
response.Redirect(request.GetPathUrl() + '/' + defaultDoc);
return;
}
}
if (!fi.Exists)
throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
}
var strHeader = request.Headers["If-Modified-Since"];
try
{
if (strHeader != null)
{
var dtIfModifiedSince = DateTime.ParseExact(strHeader, "r", null);
var ftime = fi.LastWriteTime.ToUniversalTime();
if (ftime <= dtIfModifiedSince)
{
response.ContentType = MimeTypes.GetMimeType(fileName);
response.StatusCode = 304;
return;
}
}
}
catch { }
try
{
var lastWT = fi.LastWriteTime.ToUniversalTime();
response.AddHeader("Last-Modified", lastWT.ToString("r"));
response.ContentType = MimeTypes.GetMimeType(fileName);
if (!Env.IsMono)
{
response.TransmitFile(fileName);
}
else
{
response.WriteFile(fileName);
}
}
catch (Exception)
{
throw new HttpException(403, "Forbidden.");
}
}
示例12: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.EndHttpRequest(skipClose: true, afterBody: r => {
// i.e. /static/folder/file.html => folder/file.html
var requested_relative_path = request.GetAbsolutePath().Substring(RoutePath.Length);
var fileName = Path.Combine (HtdocsPath, requested_relative_path);
var fi = new FileInfo(fileName);
if (!fi.Exists)
{
// append default filename if feasible (i.e. index.html)
if ((fi.Attributes & FileAttributes.Directory) != 0)
{
foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
{
var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
if (!File.Exists(defaultFileName)) continue;
r.Redirect(request.GetPathUrl() + '/' + defaultDoc);
return;
}
}
var msg = "Static File '" + request.PathInfo + "' not found.";
throw new HttpException(404, msg);
}
TimeSpan maxAge;
if (r.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(r.ContentType, out maxAge))
{
r.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
}
if (request.HasNotModifiedSince(fi.LastWriteTime))
{
r.ContentType = MimeTypes.GetMimeType(fileName);
r.StatusCode = 304;
return;
}
try
{
r.AddHeaderLastModified(fi.LastWriteTime);
r.ContentType = MimeTypes.GetMimeType(fileName);
if (!Env.IsMono)
{
r.TransmitFile(fileName);
}
else
{
r.WriteFile(fileName);
}
}
catch (Exception ex)
{
//log.ErrorFormat("Static file {0} forbidden: {1}", request.PathInfo, ex.Message);
throw new HttpException(403, "Forbidden.");
}
});
}