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


C# IHttpResponse.EndHttpRequest方法代码示例

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


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

示例1: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            response.ContentType = "text/plain";
            response.StatusCode = 403;

		    response.EndHttpRequest(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 (!ServiceStackHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
                    r.Write("\nApp.DebugLastHandlerArgs: " + ServiceStackHttpHandlerFactory.DebugLastHandlerArgs);
            });
		}
开发者ID:grammarware,项目名称:fodder,代码行数:29,代码来源:src_ServiceStack_WebHost_Endpoints_Support_ForbiddenHttpHandler.cs

示例2: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            httpRes.ContentType = ContentType.Html;
            if (RazorFormat == null)
                RazorFormat = RazorFormat.Instance;

            var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
            if (contentPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                httpRes.EndHttpRequest();
                return;
            }

            if (RazorFormat.WatchForModifiedPages)
                RazorFormat.ReloadIfNeeeded(contentPage);

            //Add good caching support
            //if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
            //    return;

            var model = Model;
            if (model == null)
                httpReq.Items.TryGetValue("Model", out model);
            if (model == null)
            {
                var modelType = RazorPage != null ? RazorPage.GetRazorTemplate().ModelType : null;
                model = modelType == null || modelType == typeof(DynamicRequestObject)
                    ? null
                    : DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
            }

            RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
        }
开发者ID:robertgreen,项目名称:ServiceStack,代码行数:34,代码来源:RazorHandler.cs

示例3: 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.EndHttpRequest(skipClose:true);
        }
开发者ID:grammarware,项目名称:fodder,代码行数:34,代码来源:src_ServiceStack_WebHost_Endpoints_Support_RedirectHttpHandler.cs

示例4: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            httpRes.ContentType = ContentType.Html;
            if (RazorFormat == null)
                RazorFormat = RazorFormat.Instance;

            var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
            if (contentPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                httpRes.EndHttpRequest();
                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);
        }
开发者ID:pruiz,项目名称:ServiceStack,代码行数:27,代码来源:RazorHandler.cs

示例5: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            Log.ErrorFormat("{0} Request not found: {1}", request.UserHostAddress, request.RawUrl);

            var text = new StringBuilder("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).ToString();

            response.ContentType = "text/plain";
            response.StatusCode = 404;
            response.EndHttpRequest(skipClose: true, afterBody: r => r.Write(text));
        }
开发者ID:rajeshpillai,项目名称:ServiceStack,代码行数:15,代码来源:NotFoundHttpHandler.cs

示例6: 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.AbsoluteUri.WithTrailingSlash() + this.RelativeUrl;
                response.StatusCode = (int)HttpStatusCode.Redirect;
                response.AddHeader(HttpHeaders.Location, absoluteUrl);
            }

            response.EndHttpRequest(skipClose:true);
        }
开发者ID:rajeshpillai,项目名称:ServiceStack,代码行数:25,代码来源:RedirectHttpHandler.cs

示例7: 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.EndHttpRequest();
                return;
            }

            MarkdownFormat.ReloadModifiedPageAndTemplates(contentPage);

            if (httpReq.DidReturn304NotModified(contentPage.GetLastModified(), httpRes))
                return;

            MarkdownFormat.ProcessMarkdownPage(httpReq, contentPage, null, httpRes);
        }
开发者ID:caslt,项目名称:ServiceStack,代码行数:20,代码来源:MarkdownHandler.cs

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

示例9: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            response.EndHttpRequest(skipClose: true, afterBody: r =>
            {
                var requestedPath = request.GetPhysicalPath();
                var fi = new FileInfo(requestedPath);
                foreach (var defaultDoc in EndpointHost.Config.DefaultDocuments)
                {
                    var defaultFileName = Path.Combine(fi.FullName, defaultDoc);
                    if (!File.Exists(defaultFileName)) continue;
                    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(defaultFileName);
                        r.StatusCode = 304;
                        return;
                    }

                    try
                    {
                        r.AddHeaderLastModified(fi.LastWriteTime);
                        r.ContentType = MimeTypes.GetMimeType(defaultFileName);

                        if (defaultFileName.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(defaultFileName);
                        }
                        else
                        {
                            r.WriteFile(defaultFileName);
                        }
                    }
                    catch (Exception ex)
                    {
                        log.ErrorFormat("Static file {0} forbidden: {1}", request.PathInfo, ex.Message);
                        throw new HttpException(403, "Forbidden.");
                    }
                    return;
                }
            });
        }
开发者ID:wiggle,项目名称:papercut-web,代码行数:56,代码来源:Program.cs

示例10: 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 file_content = ReadInEmbeddedResource (requested_relative_path);

                if (file_content == null)
                    throw new HttpException(404, "Not found");

                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.ContentType = MimeTypes.GetMimeType(requested_relative_path);
                    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:BooTeK,项目名称:Rainy,代码行数:39,代码来源:EmbeddedResourceHandler.cs

示例11: 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)
                        throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
                }

                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)
                {
                    throw new HttpException(403, "Forbidden.");
                }
            });
        }
开发者ID:rajeshpillai,项目名称:ServiceStack,代码行数:66,代码来源:StaticFileHandler.cs

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

示例13: ResolveAndExecuteRazorPage

        private void ResolveAndExecuteRazorPage( IHttpRequest request, IHttpResponse response, object dto )
        {
            var path = NormalizePath( request, dto );

            var razorPage = this.viewManager.GetRazorView( path );

            if ( razorPage == null )
            {
                response.StatusCode = (int)HttpStatusCode.NotFound;
                response.EndHttpRequest();
                return;
            }

            buildManager.EnsureCompiled( razorPage, response );

            //don't proceed any further, the background compiler
            //found there was a problem compiling the page, so throw
            //that compilation error.
            if ( razorPage.CompileException != null )
            {
                throw razorPage.CompileException;
            }

            //else, EnsureCompiled() ensures we have 
            //a page type to work with so, create an instance of the page
            var page = razorPage.ActivateInstance();

            //poor man's IOC -- for the razor pages.
            page.Request = request;
            page.Response = response;
            page.Output = new StreamWriter( page.Response.OutputStream );

            //deserialize the model.
            PrepareAndSetModel( page, request, dto );

            //execute the page.
            page.Execute();
            page.Output.Flush();
        }
开发者ID:HansS,项目名称:ServiceStack,代码行数:39,代码来源:PageResolver.cs


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