当前位置: 首页>>代码示例>>C#>>正文


C# IHttpResponse.AddHeaderLastModified方法代码示例

本文整理汇总了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.");
            }
        }
开发者ID:bman654,项目名称:ServiceStack,代码行数:49,代码来源:StaticFileHandler.cs

示例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;
        }
开发者ID:Arxisos,项目名称:ServiceStack,代码行数:27,代码来源:MarkdownFormat.cs

示例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.");
            }
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:66,代码来源:StaticFileHandler.cs


注:本文中的IHttpResponse.AddHeaderLastModified方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。