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


C# IResponse.EndRequest方法代码示例

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


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

示例1: ProcessRequest

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

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

示例2: Execute

        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (HostContext.HasValidAuthSecret(req))
                return;

            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();

            var authRepo = HostContext.AppHost.GetAuthRepository(req);
            using (authRepo as IDisposable)
            {
                if (session != null && session.HasRole(RoleNames.Admin, authRepo))
                    return;

                if (HasAnyPermissions(req, session, authRepo)) return;
            }

            if (DoHtmlRedirectIfConfigured(req, res)) return;

            res.StatusCode = (int)HttpStatusCode.Forbidden;
            res.StatusDescription = ErrorMessages.InvalidPermission;
            res.EndRequest();
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:25,代码来源:RequiresAnyPermission.cs

示例3: Execute

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

            if (HostContext.HasValidAuthSecret(req))
                return;

            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 {this.Provider ?? "any"} provider");
                res.EndRequest();
                return;
            }

            req.PopulateFromRequestIfHasSessionId(requestDto);

            //Call before GetSession so Exceptions can bubble
            req.Items[Keywords.HasPreAuthenticated] = true;
            matchingOAuthConfigs.OfType<IAuthWithRequest>()
                .Each(x => x.PreAuthenticate(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:AVee,项目名称:ServiceStack,代码行数:35,代码来源:AuthenticateAttribute.cs

示例4: Execute

        public override void Execute(IRequest req, IResponse 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:tystol,项目名称:ServiceStack,代码行数:32,代码来源:AuthenticateAttribute.cs

示例5: Execute

        public override void Execute(IRequest req, IResponse 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:vebin,项目名称:soa,代码行数:14,代码来源:RequiresAnyPermission.cs

示例6: Execute

        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (SkipIfDebugMode && HostContext.Config.DebugMode)
                return;

            if (!req.IsSecureConnection)
            {
                if (SkipIfXForwardedFor)
                {
                    var httpReq = req as IHttpRequest;
                    if (httpReq != null && httpReq.XForwardedFor != null)
                        return;
                }

                res.RedirectToUrl(req.AbsoluteUri.AsHttps());
                res.EndRequest();
            }
        }
开发者ID:BilliamBrown,项目名称:ServiceStack,代码行数:18,代码来源:EnsureHttpsAttribute.cs

示例7: Execute

        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (HostContext.AppHost.HasValidAuthSecret(req))
                return;

            base.Execute(req, res, requestDto);
            if (res.IsClosed)
                return;

            var session = req.GetSession();
            if (session != null && session.HasRole("Admin")
                || (this.HasWebSudo(req, session as IWebSudoAuthSession)
                || this.DoHtmlRedirectIfConfigured(req, res)))
                return;

            res.StatusCode = 402;
            res.StatusDescription = "Web Sudo Required";
            res.EndRequest();
        }
开发者ID:jin29neci,项目名称:ServiceStack,代码行数:19,代码来源:WebSudoRequiredAttribute.cs

示例8: Execute

        public override void Execute(IRequest req, IResponse res, object requestDto)
        {
            if (HostContext.AppHost.HasValidAuthSecret(req))
                return;

            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 (session != null && session.HasRole(RoleNames.Admin))
                return;

            if (HasAllRoles(req, session)) return;

            if (DoHtmlRedirectIfConfigured(req, res)) return;

            res.StatusCode = (int)HttpStatusCode.Forbidden;
            res.StatusDescription = "Invalid Role";
            res.EndRequest();
        }
开发者ID:GDBSD,项目名称:ServiceStack,代码行数:21,代码来源:RequiredRoleAttribute.cs

示例9: HandleException

        protected Task HandleException(IRequest httpReq, IResponse httpRes, string operationName, Exception ex)
        {
            var errorMessage = $"Error occured while Processing Request: {ex.Message}";
            HostContext.AppHost.OnLogError(typeof(HttpAsyncTaskHandler), errorMessage, ex);

            try
            {
                HostContext.RaiseAndHandleUncaughtException(httpReq, httpRes, operationName, ex);
                return TypeConstants.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:AVee,项目名称:ServiceStack,代码行数:22,代码来源:HttpAsyncTaskHandler.cs

示例10: OnFailedAuthentication

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

示例11: HandleFailedAuth

        public static void HandleFailedAuth(IAuthProvider authProvider,
            IAuthSession session, IRequest httpReq, IResponse 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:dittodhole,项目名称:dotnet-ServiceStack,代码行数:16,代码来源:AuthProvider.cs

示例12: OnFailedAuthentication

 public override void OnFailedAuthentication(IAuthSession session, IRequest httpReq, IResponse 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:jango2015,项目名称:ServiceStack,代码行数:9,代码来源:DigestAuthProvider.cs

示例13: HandleException

        protected Task HandleException(IRequest httpReq, IResponse 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:softwx,项目名称:ServiceStack,代码行数:22,代码来源:HttpAsyncTaskHandler.cs

示例14: ProcessRequest

        /// <summary>
        /// This is called by the hosting environment via CatchAll usually for content pages.
        /// </summary>
        public override void ProcessRequest(IRequest httpReq, IResponse httpRes, string operationName)
        {
            HostContext.ApplyCustomHandlerRequestFilters(httpReq, httpRes);
            if (httpRes.IsClosed) return;

            httpRes.ContentType = MimeTypes.Html;

            var contentPage = ResolveContentPage(httpReq);
            using (ExecuteRazorPage(httpReq, httpRes, null, contentPage)) 
            { 
                httpRes.EndRequest(skipHeaders: true);
            }
        }
开发者ID:BilliamBrown,项目名称:ServiceStack,代码行数:16,代码来源:RazorPageResolver.cs

示例15: OnFailedAuthentication

 public override void OnFailedAuthentication(IAuthSession session, IRequest httpReq, IResponse httpRes)
 {
     httpRes.StatusCode = (int)HttpStatusCode.Unauthorized;
     //Needs to be 'Basic ' in order for HttpWebRequest to accept challenge and send NetworkCredentials
     httpRes.AddHeader(HttpHeaders.WwwAuthenticate, $"Basic realm=\"{this.AuthRealm}\"");
     httpRes.EndRequest();
 }
开发者ID:AVee,项目名称:ServiceStack,代码行数:7,代码来源:ApiKeyAuthProvider.cs


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