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


C# IHttpResponse.EndRequest方法代码示例

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


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

示例1: Execute

        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            if (AuthenticateService.AuthProviders == null)
                throw new InvalidOperationException(
                    "The AuthService must be initialized by calling AuthService.Init to use an authenticate attribute");

            var matchingOAuthConfigs = AuthenticateService.AuthProviders.Where(x =>
                this.Provider.IsNullOrEmpty()
                || x.Provider == this.Provider).ToList();

            if (matchingOAuthConfigs.Count == 0)
            {
                res.WriteError(req, requestDto, "No OAuth Configs found matching {0} provider"
                    .Fmt(this.Provider ?? "any"));
                res.EndRequest();
                return;
            }

            if (matchingOAuthConfigs.Any(x => x.Provider == DigestAuthProvider.Name))
                AuthenticateIfDigestAuth(req, res);

            if (matchingOAuthConfigs.Any(x => x.Provider == BasicAuthProvider.Name))
                AuthenticateIfBasicAuth(req, res);

            var session = req.GetSession();
            if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
            {
                if (this.DoHtmlRedirectIfConfigured(req, res, true)) return;

                AuthProvider.HandleFailedAuth(matchingOAuthConfigs[0], session, req, res);
            }
        }
开发者ID:qqqzhch,项目名称:ServiceStack,代码行数:32,代码来源:AuthenticateAttribute.cs

示例2: ProcessRequest

        /// <summary>
        /// This is called by the hosting environment via CatchAll usually for content pages.
        /// </summary>
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            httpRes.ContentType = MimeTypes.Html;

            ResolveAndExecuteRazorPage(httpReq, httpRes, null);
            httpRes.EndRequest(skipHeaders: true);
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:10,代码来源:RazorPageResolver.cs

示例3: WriteDebugResponse

        public static void WriteDebugResponse(IHttpResponse httpRes, object response)
        {
            httpRes.WriteToResponse(response, WriteDebugRequest,
                new SerializationContext(ContentType.PlainText));

            httpRes.EndRequest();
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:7,代码来源:JsvSyncReplyHandler.cs

示例4: HandleOAuth2Exception

 private static void HandleOAuth2Exception(IHttpRequest req, IHttpResponse res, ProtocolFaultResponseException ex) {
     var response = ex.CreateErrorResponse();
     if (ex.ErrorResponseMessage is UnauthorizedResponse) {
         var oauth2Error = ex.ErrorResponseMessage as UnauthorizedResponse;
         response.Body = JsonSerializer.SerializeToString(oauth2Error.ToOAuth2JsonResponse());
         response.Headers[HttpResponseHeader.ContentType] = "application/json";
     }
     var context = ((HttpRequest)req.OriginalRequest).RequestContext.HttpContext;
     response.Respond(context);
     res.EndRequest();
 }
开发者ID:chengming0916,项目名称:OAuthStack,代码行数:11,代码来源:RequireOAuth2ScopeAttribute.cs

示例5: Execute

        /// <summary>This method is only executed if the HTTP method matches the <see cref="ApplyTo"/> property.</summary>
        ///
        /// <param name="req">       The http request wrapper.</param>
        /// <param name="res">       The http response wrapper.</param>
        /// <param name="requestDto">The request DTO.</param>
        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            base.Execute(req, res, requestDto); //first check if session is authenticated
            if (res.IsClosed) return; //AuthenticateAttribute already closed the request (ie auth failed)

            var session = req.GetSession();
            if (HasAnyPermissions(req, session)) return;

            if (DoHtmlRedirectIfConfigured(req, res)) return;

            res.StatusCode = (int)HttpStatusCode.Forbidden;
            res.StatusDescription = "Invalid Permission";
            res.EndRequest();
        }
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:19,代码来源:RequiresAnyPermission.cs

示例6: RequestFilter

        public void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            if (!string.IsNullOrEmpty(allowedOrigins))
                res.AddHeader(HttpHeaders.AllowOrigin, allowedOrigins);
            if (!string.IsNullOrEmpty(allowedMethods))
                res.AddHeader(HttpHeaders.AllowMethods, allowedMethods);
            if (!string.IsNullOrEmpty(allowedHeaders))
                res.AddHeader(HttpHeaders.AllowHeaders, allowedHeaders);
            if (allowCredentials)
                res.AddHeader(HttpHeaders.AllowCredentials, "true");

            if (AutoHandleOptionRequests && req.HttpMethod == HttpMethods.Options)
                res.EndRequest();
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:14,代码来源:EnableCorsAttribute.cs

示例7: HandleFailedAuth

        public static void HandleFailedAuth(IAuthProvider authProvider,
            IAuthSession session, IHttpRequest httpReq, IHttpResponse httpRes)
        {
            var baseAuthProvider = authProvider as AuthProvider;
            if (baseAuthProvider != null)
            {
                baseAuthProvider.OnFailedAuthentication(session, httpReq, httpRes);
                return;
            }

            httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
            httpRes.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\""
                .Fmt(authProvider.Provider, authProvider.AuthRealm));

            httpRes.EndRequest();
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:16,代码来源:AuthProvider.cs

示例8: OnFailedAuthentication

 public virtual void OnFailedAuthentication(IAuthSession session, IHttpRequest httpReq, IHttpResponse httpRes)
 {
     httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
     httpRes.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\"".Fmt(this.Provider, this.AuthRealm));
     httpRes.EndRequest();
 }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:6,代码来源:AuthProvider.cs

示例9: ProcessRequest

        /// <summary>
        /// Called by the HtmlFormat:IPlugin who checks to see if any registered view engines can handle the response DTO.
        /// If this view engine can handle the response DTO, then process it, otherwise, returning false will
        /// allow another view engine to attempt to process it. If no view engines can process the DTO,
        /// HtmlFormat will simply handle it itself.
        /// </summary>
        public virtual bool ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, object dto)
        {
            //for compatibility
            var httpResult = dto as IHttpResult;
            if (httpResult != null)
                dto = httpResult.Response;

            var existingRazorPage = FindRazorPage(httpReq, dto);
            if (existingRazorPage == null)
            {
                return false;
            }

            ResolveAndExecuteRazorPage(httpReq, httpRes, dto, existingRazorPage);

            httpRes.EndRequest();
            return true;
        }
开发者ID:yeurch,项目名称:ServiceStack,代码行数:24,代码来源:RazorPageResolver.cs

示例10: ProcessRequest

        /// <summary>
        /// This is called by the hosting environment via CatchAll usually for content pages.
        /// </summary>
        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            ////ToDo: Figure out binary assets like jpgs and pngs. 

            httpRes.ContentType = ContentType.PlainText;

            if (httpReq.PathInfo.EndsWith("js"))
            {
                httpRes.ContentType = ContentType.JavaScript;
            }
            else if (httpReq.PathInfo.EndsWith("css"))
            {
                httpRes.ContentType = ContentType.css;
            }

            this.ResolveRazorPageAsset(httpReq, httpRes, null);
            httpRes.EndRequest(skipHeaders: true);
        }
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:21,代码来源:RazorPageResolver.cs

示例11: HandleException

        protected void HandleException(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, Exception ex)
        {
            var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
            Log.Error(errorMessage, ex);

            try
            {
                EndpointHost.ExceptionHandler(httpReq, httpRes, operationName, ex);
            }
            catch (Exception writeErrorEx)
            {
                //Exception in writing to response should not hide the original exception
                Log.Info("Failed to write error to response: {0}", writeErrorEx);
                //rethrow the original exception
                throw ex;
            }
            finally
            {
                httpRes.EndRequest(skipHeaders: true);
            }
        }
开发者ID:jmaucher,项目名称:SStack,代码行数:21,代码来源:EndpointHandlerBase.cs

示例12: HandleException

        protected Task HandleException(IHttpRequest httpReq, IHttpResponse httpRes, string operationName, Exception ex)
        {
            var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
            Log.Error(errorMessage, ex);

            try
            {
                HostContext.RaiseUncaughtException(httpReq, httpRes, operationName, ex);
                return EmptyTask;
            }
            catch (Exception writeErrorEx)
            {
                //Exception in writing to response should not hide the original exception
                Log.Info("Failed to write error to response: {0}", writeErrorEx);
                //rethrow the original exception
                return ex.AsTaskException();
            }
            finally
            {
                httpRes.EndRequest(skipHeaders: true);
            }
        }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:22,代码来源:ServiceStackHandlerBase.cs

示例13: OnFailedAuthentication

 public override void OnFailedAuthentication(IAuthSession session, IHttpRequest httpReq, IHttpResponse httpRes)
 {
     var digestHelper = new DigestAuthFunctions();
     httpRes.StatusCode = (int) HttpStatusCode.Unauthorized;
     httpRes.AddHeader(
         HttpHeaders.WwwAuthenticate,
         "{0} realm=\"{1}\", nonce=\"{2}\", qop=\"auth\"".Fmt(Provider, AuthRealm, digestHelper.GetNonce(httpReq.UserHostAddress, PrivateKey)));
     httpRes.EndRequest();
 }
开发者ID:rjdudley,项目名称:ServiceStack,代码行数:9,代码来源:DigestAuthProvider.cs

示例14: ResponseFilter

        public void ResponseFilter(IHttpRequest req, IHttpResponse res, object responseDto)
        {
            using (var ms = new MemoryStream())
            {
                EndpointHost.ContentTypeFilter.SerializeToStream(
                    new SerializationContext(req.ResponseContentType), responseDto, ms);

                var bytes = ms.ToArray();

                var listenerResponse = (HttpListenerResponse)res.OriginalResponse;
                listenerResponse.ContentType = "application/json";
                listenerResponse.SendChunked = false;
                listenerResponse.ContentLength64 = bytes.Length;
                listenerResponse.OutputStream.Write(bytes, 0, bytes.Length);

                res.EndRequest ();
            }
        }
开发者ID:Dynalon,项目名称:Rainy,代码行数:18,代码来源:Common.cs


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