本文整理汇总了C#中IHttpResponse.AddHeaderLastModified方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpResponse.AddHeaderLastModified方法的具体用法?C# IHttpResponse.AddHeaderLastModified怎么用?C# IHttpResponse.AddHeaderLastModified使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHttpResponse
的用法示例。
在下文中一共展示了IHttpResponse.AddHeaderLastModified方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
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.");
}
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: ProcessMarkdownPage
public bool ProcessMarkdownPage(IHttpRequest httpReq, MarkdownPage markdownPage, object dto, IHttpResponse httpRes)
{
httpRes.AddHeaderLastModified(markdownPage.GetLastModified());
var renderInTemplate = true;
var renderHtml = true;
string format;
if (httpReq != null && (format = httpReq.QueryString["format"]) != null)
{
renderHtml = !(format.StartsWithIgnoreCase("markdown")
|| format.StartsWithIgnoreCase("text")
|| format.StartsWithIgnoreCase("plain"));
renderInTemplate = !httpReq.GetFormatModifier().StartsWithIgnoreCase("bare");
}
if (!renderHtml)
{
httpRes.ContentType = ContentType.PlainText;
}
var template = httpReq.GetTemplate();
var markup = RenderDynamicPage(markdownPage, markdownPage.Name, dto, renderHtml, renderInTemplate, template);
var markupBytes = markup.ToUtf8Bytes();
httpRes.OutputStream.Write(markupBytes, 0, markupBytes.Length);
return true;
}
示例3: ProcessRequest
public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
{
ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
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 (fileName.EqualsIgnoreCase(this.DefaultFilePath))
{
if (fi.LastWriteTime > this.DefaultFileModified)
SetDefaultFile(this.DefaultFilePath); //reload
response.OutputStream.Write(this.DefaultFileContents, 0, this.DefaultFileContents.Length);
response.Close();
return;
}
if (!Env.IsMono)
{
response.TransmitFile(fileName);
}
else
{
response.WriteFile(fileName);
}
}
catch (Exception)
{
throw new HttpException(403, "Forbidden.");
}
}