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


C# IHttpResponse.EndServiceStackRequest方法代码示例

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


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

示例1: WriteDebugResponse

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

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

示例2: AuthenticateBasicAuth

        //Also shared by RequiredRoleAttribute and RequiredPermissionAttribute
        public static User AuthenticateBasicAuth(IHttpRequest req, IHttpResponse res)
        {
            var userCredentialsPair = req.GetBasicAuthUserAndPassword();
            var email = userCredentialsPair.HasValue ? userCredentialsPair.Value.Key : String.Empty;
            var password = userCredentialsPair.HasValue ? userCredentialsPair.Value.Value : String.Empty;

            User user = null;
            bool isValid = false;

            using (var session = NHibernateHelper.OpenSession())
            {
                using (var transaction = session.BeginTransaction())
                {
                    var userQuery = session.QueryOver<User>()
                        .Where(table => table.Email == email)
                        .And(table => table.Password == password);

                    user = userQuery.SingleOrDefault();

                    transaction.Commit();

                    isValid = (user != null);
                }
            }

            if (!isValid)
            {
                res.StatusCode = (int)HttpStatusCode.Unauthorized;
                res.EndServiceStackRequest();
            }

            return user;
        }
开发者ID:jasonpang,项目名称:Meetup,代码行数:34,代码来源:RequiresAuthenticationAttribute.cs

示例3: HandleException

        private static void HandleException(IHttpRequest request, IHttpResponse response,
		                                    string operation_name, Exception e,
		                                    object request_dto = null)
        {
            // log the exception
            ILog logger = LogManager.GetLogger (typeof(ExceptionHandler));

            // create appropriate response
            if (e is UnauthorizedException) {
                var ex = (UnauthorizedException) e;
                logger.Debug (ex.ErrorMessage);
                response.StatusCode = 401;
                response.StatusDescription = "Unauthorized";
                response.ContentType = request.ContentType;
                // TODO provide JSON error objects
            } else if (e is ValidationException) {
                var ex = (ValidationException) e;
                logger.Debug (ex.ErrorMessage);
                response.StatusCode = 400;
                response.StatusDescription = "Bad request. Detail:" + e.Message;
            } else if (e is RainyBaseException) {
                var ex = (RainyBaseException) e;
                logger.Debug (ex.ErrorMessage);
                response.StatusCode = 400;
                response.StatusDescription = ex.ErrorMessage;
            } else {
                logger.Debug (e.Message);
                response.StatusCode = 500;
                response.StatusDescription = "Internal server error.";
            }
            response.EndServiceStackRequest ();
        }
开发者ID:BooTeK,项目名称:Rainy,代码行数:32,代码来源:ErrorHandling.cs

示例4: Execute

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

            var matchingOAuthConfigs = AuthService.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.EndServiceStackRequest();
                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:JonCanning,项目名称:ServiceStack,代码行数:31,代码来源:AuthenticateAttribute.cs

示例5: 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 = ContentType.Html;

            ResolveAndExecuteRazorPage(httpReq, httpRes, null);

            httpRes.EndServiceStackRequest( skipHeaders: true );
        }
开发者ID:HansS,项目名称:ServiceStack,代码行数:11,代码来源:PageResolver.cs

示例6: Execute

 public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
 {
     var originalRequest = (HttpRequest)req.OriginalRequest;
     var identity = originalRequest.RequestContext.HttpContext.User.Identity;
     if (!identity.IsAuthenticated)
     {
         res.StatusCode = (int)HttpStatusCode.Forbidden;
         res.EndServiceStackRequest(skipHeaders: true);
     }
 }
开发者ID:olgerd007,项目名称:ordersDemo,代码行数:10,代码来源:SomeTests.cs

示例7: Execute

        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            AuthenticateAttribute.AuthenticateIfBasicAuth(req, res);

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

            res.StatusCode = (int)HttpStatusCode.Unauthorized;
            res.StatusDescription = "Invalid Permissions";
            res.EndServiceStackRequest();
        }
开发者ID:ToniKielo,项目名称:ServiceStack,代码行数:11,代码来源:RequiredPermissionAttribute.cs

示例8: Execute

        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;

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

示例9: Execute

        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            AuthenticateAttribute.AuthenticateIfBasicAuth(req, res);

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

            res.StatusCode = session != null && session.IsAuthenticated
                ? (int)HttpStatusCode.Forbidden
                : (int)HttpStatusCode.Unauthorized;
            res.StatusDescription = "Invalid Role";
            res.EndServiceStackRequest();
        }
开发者ID:grammarware,项目名称:fodder,代码行数:13,代码来源:src_ServiceStack_ServiceInterface_RequiredRoleAttribute.cs

示例10: HandleException

        private static void HandleException(IHttpRequest request, IHttpResponse response,
		                                    string operation_name, Exception e,
		                                    object request_dto = null)
        {
            // log the exception
            ILog logger = LogManager.GetLogger (typeof(ExceptionHandler));

            // create appropriate response
            if (e is UnauthorizedException) {
                var ex = (UnauthorizedException) e;
                //logger.Debug (ex.ErrorMessage);
                //LogExceptionDetails (logger, e);
                if (ex.UserStatus.StartsWith ("Moderation")) {
                    response.StatusCode = 412;
                    response.StatusDescription = ex.UserStatus;
                    response.ContentType = request.ContentType;
                } else {
                    response.StatusCode = 401;
                    response.StatusDescription = "Unauthorized.";
                    response.ContentType = request.ContentType;
                }
                // TODO provide JSON error objects
            } else if (e is ValidationException) {
                var ex = (ValidationException) e;
                logger.Debug (ex.ErrorMessage);
                LogExceptionDetails (logger, e);
                response.StatusCode = 400;
                response.StatusDescription = "Bad request. Detail:" + e.Message;
            } else if (e is RainyBaseException) {
                var ex = (RainyBaseException) e;
                logger.Debug (ex.ErrorMessage);
                LogExceptionDetails (logger, e);
                response.StatusCode = 400;
                response.StatusDescription = ex.ErrorMessage;
            } else {
                logger.Debug (e.Message);
                LogExceptionDetails (logger, e);
                response.StatusCode = 500;
                response.StatusDescription = "Internal server error.";
            }
            // display nice message if viewed in browser
            if (request.AcceptTypes.Contains ("text/html")) {
                response.Write ("<h1>" + response.StatusCode + "</h1>" +
                    "<p>" + response.StatusDescription + "</p>");
            }
            response.EndServiceStackRequest ();
            throw e;
        }
开发者ID:rashoodkhan,项目名称:Rainy,代码行数:48,代码来源:ErrorHandling.cs

示例11: Execute

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

            var matchingOAuthConfigs = AuthService.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.EndServiceStackRequest();
                return;
            }

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

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

            using (var cache = req.GetCacheClient())
            {
                var session = req.GetSession();

                if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
                {
                    var htmlRedirect = HtmlRedirect ?? AuthService.HtmlRedirect;
                    if (htmlRedirect != null && req.ResponseContentType.MatchesContentType(ContentType.Html))
                    {
                        var url = htmlRedirect;
                        if (url.SafeSubstring(0, 2) == "~/")
                        {
                            url = req.GetBaseUrl().CombineWith(url.Substring(2));
                        }
                        url = url.AddQueryParam("redirect", req.AbsoluteUri);
                        res.RedirectToUrl(url);
                        return;
                    }

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

示例12: Execute

        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 (HasAllPermissions(req, session)) return;
            
            var htmlRedirect = HtmlRedirect ?? AuthService.HtmlRedirect;
            if (htmlRedirect != null && req.ResponseContentType.MatchesContentType(ContentType.Html))
            {
                var url = req.ResolveAbsoluteUrl(htmlRedirect);
                res.RedirectToUrl(url);
                return;
            }

            res.StatusCode = (int)HttpStatusCode.Forbidden;
            res.StatusDescription = "Invalid Permission";
            res.EndServiceStackRequest();
        }
开发者ID:hp-zhoujinqiao,项目名称:ServiceStack-1,代码行数:20,代码来源:RequiredPermissionAttribute.cs

示例13: 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.EndServiceStackRequest(skipHeaders: true);
            }
        }
开发者ID:rossbeehler,项目名称:ServiceStack,代码行数:16,代码来源:EndpointHandlerBase.cs

示例14: HandleException

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

            try
            {
                var statusCode = ex.ToStatusCode();
                //httpRes.WriteToResponse always calls .Close in it's finally statement so
                //if there is a problem writing to response, by now it will be closed
                if (!httpRes.IsClosed)
                {
                    httpRes.WriteErrorToResponse(responseContentType, operationName, errorMessage, ex, statusCode);
                }
            }
            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.EndServiceStackRequest(skipHeaders: true);
            }
        }
开发者ID:cyberprune,项目名称:ServiceStack,代码行数:27,代码来源:EndpointHandlerBase.cs

示例15: 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.EndServiceStackRequest();
            return true;
        }
开发者ID:pwhe23,项目名称:ServiceStack,代码行数:24,代码来源:RazorPageResolver.cs


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