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


C# IHttpRequest.GetAbsolutePath方法代码示例

本文整理汇总了C#中IHttpRequest.GetAbsolutePath方法的典型用法代码示例。如果您正苦于以下问题:C# IHttpRequest.GetAbsolutePath方法的具体用法?C# IHttpRequest.GetAbsolutePath怎么用?C# IHttpRequest.GetAbsolutePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHttpRequest的用法示例。


在下文中一共展示了IHttpRequest.GetAbsolutePath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: 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.");
                }
            });
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:47,代码来源:EmbeddedResourceHandler.cs

示例2: CheckAndProcess

        public IHttpHandler CheckAndProcess(IHttpRequest request)
        {
            var abs_path = request.GetAbsolutePath();

            if (abs_path.StartsWith ("/resource")) {
                return null;
            }

            if (abs_path.StartsWith ("/oauth/") || abs_path.StartsWith ("/api/")) {
                return null;
            } else if (abs_path.StartsWith ("/admin/") || abs_path.StartsWith ("swagger-ui")) {
                return this;
            } else if (abs_path.Count (c => c == '/') == 1) {
                return this;
            } else {
                return null;
            }
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:18,代码来源:EmbeddedResourceHandler.cs

示例3: 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.");
                }
            });
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:68,代码来源:FilesystemHandler.cs

示例4: CheckAndProcess

        public IHttpHandler CheckAndProcess(IHttpRequest request)
        {
            var abs_path = request.GetAbsolutePath();

            // TODO case insensitive on option
            if (abs_path.StartsWith(RoutePath))
                // we want to handle this url path
                return this;
            else
                return null;
        }
开发者ID:BooTeK,项目名称:Rainy,代码行数:11,代码来源:EmbeddedResourceHandler.cs

示例5: CheckAndProcess

        public IHttpHandler CheckAndProcess(IHttpRequest request)
        {
            if (!active)
                return null;

            string abs_path = request.GetAbsolutePath();

            if (this.HtdocsPath.Contains ("swagger-ui")) {

                if (abs_path.StartsWith ("/swagger-ui/")) {
                    return this;
                }
            }
            if (abs_path.StartsWith ("/fonts/")) {
                return this;
            }
            if (abs_path.StartsWith ("/resource")) {
                return null;
            }

            if (abs_path.StartsWith ("/oauth/") || abs_path.StartsWith ("/api/")) {
                return null;
            } else if (abs_path.StartsWith ("/admin/")) {
                return this;
            } else if (abs_path.Count (c => c == '/') == 1) {
                return this;
            } else {
                return null;
            }

            /*
            // TODO case insensitive on option
            if (abs_path.StartsWith(RoutePath) && is_html_request)
                // we want to handle this url path
                return this;
            else
                return null;
            */
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:39,代码来源:FilesystemHandler.cs


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