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


C# IHttpResponse.Close方法代码示例

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


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

示例1: Execute

        public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            var applicationRequest = requestDto as ApplicationRequest;
            var appKey = GetAppKeyFromRequest(req, applicationRequest);
            var appSecret = GetAppSecretFromRequest(req, applicationRequest);

            var app = ApplicationAuthenticationService.Authenticate(appKey,appSecret);
            if (app == null)
            {
                res.StatusCode = (int)HttpStatusCode.Forbidden;
                // Some Android devices require a body, otherwise the response code is ignored and set 0
                res.Write(HttpStatusCode.Forbidden.ToString());
                res.Close();
            }
            if (applicationRequest != null)
            {
                applicationRequest.AppKey = appKey;
                applicationRequest.AppSecret = appSecret;
                applicationRequest.Application = ApplicationRepository.FindApplication(appKey, appSecret);
                applicationRequest.Account = AccountApplicationRepository.GetForApplication(applicationRequest.Application.Id);
            }
            var validationErrors = ValidateRequest(applicationRequest);
            if (validationErrors.Any())
            {
                res.StatusCode = (int)HttpStatusCode.BadRequest;
                // Some Android devices require a body, otherwise the response code is ignored and set 0
                res.Write(HttpStatusCode.BadRequest.ToString());
                foreach (var error in validationErrors)
                {
                    res.Write(error);
                }
                res.Close();
            }
        }
开发者ID:allenarthurgay,项目名称:FederatedOauthConsumer,代码行数:34,代码来源:RequiresAppRegistrationAttribute.cs

示例2: WriteDebugResponse

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

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

示例3: WriteDebugResponse

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

            ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(httpRes);
            httpRes.Close();
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:8,代码来源:JsvSyncReplyHandler.cs

示例4: 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 = (int)HttpStatusCode.Unauthorized;
            res.StatusDescription = "Invalid Role";
            res.Close();
        }
开发者ID:niemyjski,项目名称:ServiceStack,代码行数:11,代码来源:RequiredRoleAttribute.cs

示例5: 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";
            ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(res);
            res.Close();
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:12,代码来源:RequiredPermissionAttribute.cs

示例6: Execute

 public override void Execute(IHttpRequest req, IHttpResponse res, object requestDto)
 {
     var session = req.GetSession();
     foreach (string requiredPermission in this.RequiredPermissions)
     {
         if (session == null || !session.HasPermission(requiredPermission))
         {
             res.StatusCode = (int)HttpStatusCode.Unauthorized;
             res.StatusDescription = "Invalid Permissions";
             res.Close();
             return;
         }
     }
 }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:14,代码来源:RequiredPermissionAttribute.cs

示例7: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            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.Write(text);
            response.Close();
        }
开发者ID:sbeparey,项目名称:ServiceStack,代码行数:14,代码来源:NotFoundHttpHandler.cs

示例8: 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.Write(text);
            ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
            response.Close();
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:17,代码来源:NotFoundHttpHandler.cs

示例9: 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.Close();
        }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:24,代码来源:RedirectHttpHandler.cs

示例10: Execute

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

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

            var userPass = req.GetBasicAuthUserAndPassword();
            if (userPass != null)
            {
                var authService = req.TryResolve<AuthService>();
                authService.RequestContext = new HttpRequestContext(req, res, requestDto);
                var response = authService.Post(new Auth.Auth {
                    provider = BasicAuthConfig.Name,
                    UserName = userPass.Value.Key,
                    Password = userPass.Value.Value
                });
            }

            using (var cache = req.GetCacheClient())
            {
                var sessionId = req.GetPermanentSessionId();
                var session = sessionId != null ? cache.GetSession(sessionId) : null;

                if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
                {
                    res.StatusCode = (int)HttpStatusCode.Unauthorized;
                    res.AddHeader(HttpHeaders.WwwAuthenticate, "{0} realm=\"{1}\""
                        .Fmt(matchingOAuthConfigs[0].Provider, matchingOAuthConfigs[0].AuthRealm));

                    res.Close();
                }
            }
        }
开发者ID:austinvernsonger,项目名称:ServiceStack,代码行数:44,代码来源:AuthenticateAttribute.cs

示例11: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            var resourceName = string.Concat(_assembly.GetName().Name, ".", _filePath.Replace('/', '.'));

            response.ContentType = MimeTypes.GetMimeType(_filePath);

            using(var stream = _assembly.GetManifestResourceStream(resourceName))
            {
                if (stream == null)
                {
                    response.StatusCode = (int)HttpStatusCode.NotFound;
                    response.Close();
                }
                else
                {
                    // TODO: Figure out the best way to enable browser caching of this static content.
                    response.AddHeader(HttpHeaders.CacheControl, "max-age=" + TimeSpan.FromDays(5).TotalSeconds);
                    response.SetContentLength(stream.Length);
                    stream.CopyTo(response.OutputStream);
                    response.OutputStream.Flush();
                }
            }
        }
开发者ID:shaneedwards,项目名称:FluentMigrator.ServiceStack,代码行数:23,代码来源:EmbeddedFileHandler.cs

示例12: 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.Close();
        }
开发者ID:half-evil,项目名称:ServiceStack,代码行数:16,代码来源:AuthProvider.cs

示例13: 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.Close();
 }
开发者ID:half-evil,项目名称:ServiceStack,代码行数:6,代码来源:AuthProvider.cs

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

            AuthenticateIfDigestAuth(req, res);
            AuthenticateIfBasicAuth(req, res);

            using (var cache = req.GetCacheClient())
            {
                var sessionId = req.GetSessionId();
                var session = sessionId != null ? cache.GetSession(sessionId) : null;

                if (session == null || !matchingOAuthConfigs.Any(x => session.IsAuthorized(x.Provider)))
                {
                    AuthProvider.HandleFailedAuth(matchingOAuthConfigs[0], session, req, res);
                }
            }
        }
开发者ID:half-evil,项目名称:ServiceStack,代码行数:31,代码来源:AuthenticateAttribute.cs

示例15: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);

            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;
                        response.Redirect(request.GetPathUrl() + '/' + defaultDoc);
                        return;
                    }
                }

                if (!fi.Exists)
                    throw new HttpException(404, "File '" + request.PathInfo + "' not found.");
            }

            TimeSpan maxAge;
            if (response.ContentType != null && EndpointHost.Config.AddMaxAgeForStaticMimeTypes.TryGetValue(response.ContentType, out maxAge))
            {
                response.AddHeader(HttpHeaders.CacheControl, "max-age=" + maxAge.TotalSeconds);
            }

            if (request.HasNotModifiedSince(fi.LastWriteTime))
            {
                response.ContentType = MimeTypes.GetMimeType(fileName);
                response.StatusCode = 304;
                return;
            }

            try
            {
                response.AddHeaderLastModified(fi.LastWriteTime);
                response.ContentType = MimeTypes.GetMimeType(fileName);

                if (fileName.EqualsIgnoreCase(this.DefaultFilePath))
                {
                    if (fi.LastWriteTime > this.DefaultFileModified)
                        SetDefaultFile(this.DefaultFilePath); //reload

                    response.OutputStream.Write(this.DefaultFileContents, 0, this.DefaultFileContents.Length);
                    response.Close();
                    return;
                }

                if (!Env.IsMono)
                {
                    response.TransmitFile(fileName);
                }
                else
                {
                    response.WriteFile(fileName);
                }
            }
            catch (Exception)
            {
                throw new HttpException(403, "Forbidden.");
            }
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:66,代码来源:StaticFileHandler.cs


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