本文整理汇总了C#中IHttpResponse.EndHttpHandlerRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.EndHttpHandlerRequest方法的具体用法?C# IHttpResponse.EndHttpHandlerRequest怎么用?C# IHttpResponse.EndHttpHandlerRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpResponse
的用法示例。
在下文中一共展示了IHttpResponse.EndHttpHandlerRequest方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
httpRes.ContentType = MimeTypes.Html;
if (RazorFormat == null)
RazorFormat = RazorFormat.Instance;
var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
httpRes.EndHttpHandlerRequest();
return;
}
var model = Model;
if (model == null)
httpReq.Items.TryGetValue("Model", out model);
if (model == null)
{
var modelType = RazorPage != null ? RazorPage.ModelType : null;
model = modelType == null || modelType == typeof(DynamicRequestObject)
? null
: DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
}
RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
}
示例2: ProcessRequest
/// <summary>
/// Non ASP.NET requests
/// </summary>
/// <param name="request"></param>
/// <param name="response"></param>
/// <param name="operationName"></param>
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
if (string.IsNullOrEmpty(RelativeUrl) && string.IsNullOrEmpty(AbsoluteUrl))
throw new ArgumentNullException("RelativeUrl or AbsoluteUrl");
if (!string.IsNullOrEmpty(AbsoluteUrl))
{
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, this.AbsoluteUrl);
}
else
{
var absoluteUrl = request.GetApplicationUrl();
if (!string.IsNullOrEmpty(RelativeUrl))
{
if (this.RelativeUrl.StartsWith("/"))
absoluteUrl = absoluteUrl.CombineWith(this.RelativeUrl);
else if (this.RelativeUrl.StartsWith("~/"))
absoluteUrl = absoluteUrl.CombineWith(this.RelativeUrl.Replace("~/", ""));
else
absoluteUrl = request.AbsoluteUri.CombineWith(this.RelativeUrl);
}
response.StatusCode = (int)HttpStatusCode.Redirect;
response.AddHeader(HttpHeaders.Location, absoluteUrl);
}
response.EndHttpHandlerRequest(skipClose:true);
}
示例3: ProcessRequest
/// <summary>Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.</summary>
///
/// <param name="request"> The request.</param>
/// <param name="response"> The response.</param>
/// <param name="operationName">Name of the operation.</param>
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.ContentType = "text/plain";
response.StatusCode = 403;
response.EndHttpHandlerRequest(skipClose: true, afterBody: r => {
r.Write("Forbidden\n\n");
r.Write("\nRequest.HttpMethod: " + request.HttpMethod);
r.Write("\nRequest.PathInfo: " + request.PathInfo);
r.Write("\nRequest.QueryString: " + request.QueryString);
r.Write("\nRequest.RawUrl: " + request.RawUrl);
if (IsIntegratedPipeline.HasValue)
r.Write("\nApp.IsIntegratedPipeline: " + IsIntegratedPipeline);
if (!WebHostPhysicalPath.IsNullOrEmpty())
r.Write("\nApp.WebHostPhysicalPath: " + WebHostPhysicalPath);
if (!WebHostRootFileNames.IsEmpty())
r.Write("\nApp.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
if (!ApplicationBaseUrl.IsNullOrEmpty())
r.Write("\nApp.ApplicationBaseUrl: " + ApplicationBaseUrl);
if (!DefaultRootFileName.IsNullOrEmpty())
r.Write("\nApp.DefaultRootFileName: " + DefaultRootFileName);
if (!DefaultHandler.IsNullOrEmpty())
r.Write("\nApp.DefaultHandler: " + DefaultHandler);
if (!NServiceKitHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
r.Write("\nApp.DebugLastHandlerArgs: " + NServiceKitHttpHandlerFactory.DebugLastHandlerArgs);
});
}
示例4: ProcessRequest
public override void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl);
var text = new StringBuilder();
if (HostContext.DebugMode)
{
text.AppendLine("Handler for Request not found: \n\n")
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.HttpMethod: " + request.HttpMethod)
.AppendLine("Request.PathInfo: " + request.PathInfo)
.AppendLine("Request.QueryString: " + request.QueryString)
.AppendLine("Request.RawUrl: " + request.RawUrl);
}
else
{
text.Append("404");
}
response.ContentType = "text/plain";
response.StatusCode = 404;
response.EndHttpHandlerRequest(skipClose: true, afterBody: r => r.Write(text.ToString()));
}
示例5: ProcessRequest
public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
{
if (MarkdownFormat == null)
MarkdownFormat = MarkdownFormat.Instance;
var contentPage = MarkdownPage ?? MarkdownFormat.FindByPathInfo(PathInfo);
if (contentPage == null)
{
httpRes.StatusCode = (int)HttpStatusCode.NotFound;
httpRes.EndHttpHandlerRequest();
return;
}
MarkdownFormat.ReloadModifiedPageAndTemplates(contentPage);
if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
return;
var model = Model;
if (model == null)
httpReq.Items.TryGetValue("Model", out model);
MarkdownFormat.ProcessMarkdownPage(httpReq, contentPage, model, httpRes);
}
示例6: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.EndHttpHandlerRequest (skipClose: true, afterBody: r => {
// i.e. /static/folder/file.html => folder/file.html
var requested_relative_path = request.GetAbsolutePath().Substring(RoutePath.Length);
if (requested_relative_path.Count (c => c == '.') == 0) {
// append index.html
if (requested_relative_path.EndsWith ("/")) {
requested_relative_path += "index.html";
} else
requested_relative_path += "/index.html";
}
var file_content = ReadInEmbeddedResource (requested_relative_path);
if (file_content == null)
throw new HttpException(404, "Not found");
r.ContentType = MimeTypes.GetMimeType(requested_relative_path);
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(lastModified))
{
r.StatusCode = 304;
return;
}
try
{
r.AddHeaderLastModified(lastModified);
r.ContentType = MimeTypes.GetMimeType(requested_relative_path);
r.Write(file_content);
}
catch (Exception ex)
{
//log.ErrorFormat("Static file {0} forbidden: {1}", request.PathInfo, ex.Message);
throw new HttpException(400, "Server error.");
}
});
}
示例7: 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);
//.........这里部分代码省略.........
示例8: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
response.EndHttpHandlerRequest(skipClose: true, afterBody: r => {
// i.e. /static/folder/file.html => folder/file.html
var abs_path = request.GetAbsolutePath();
string requested_relative_path = "";
if (abs_path == "/")
requested_relative_path = "./";
else
requested_relative_path = abs_path.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;
fi = new FileInfo (defaultFileName);
fileName = defaultFileName;
}
}
if (!fi.Exists) {
var msg = "Static File '" + request.PathInfo + "' not found.";
throw new HttpException(404, msg);
}
}
r.ContentType = MimeTypes.GetMimeType(fileName);
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.");
}
});
}