• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# IHttpResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: AssertAccess

        protected bool AssertAccess(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            if (!EndpointHost.Config.HasFeature(Feature.Metadata))
            {
                EndpointHost.Config.HandleErrorResponse(httpReq, httpRes, HttpStatusCode.Forbidden, "Metadata Not Available");
                return false;
            }

            if (EndpointHost.Config.MetadataVisibility != EndpointAttributes.Any)
            {
                var actualAttributes = httpReq.GetAttributes();
                if ((actualAttributes & EndpointHost.Config.MetadataVisibility) != EndpointHost.Config.MetadataVisibility)
                {
                    EndpointHost.Config.HandleErrorResponse(httpReq, httpRes, HttpStatusCode.Forbidden, "Metadata Not Visible");
                    return false;
                }
            }

            if (operationName == null) return true; //For non-operation pages we don't need to check further permissions
            if (!EndpointHost.Config.EnableAccessRestrictions) return true;
            if (!EndpointHost.Config.MetadataPagesConfig.IsVisible(httpReq, Format, operationName))
            {
                EndpointHost.Config.HandleErrorResponse(httpReq, httpRes, HttpStatusCode.Forbidden, "Service Not Available");
                return false;
            }

            return true;
        }
开发者ID:mikkelfish,项目名称:ServiceStack,代码行数:28,代码来源:BaseMetadataHandler.cs


示例2: ProcessRequest

        public new void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            EndpointHost.Config.AssertFeatures(Feature.Metadata);

            var operations = EndpointHost.ServiceOperations;

            if (httpReq.QueryString["xsd"] != null)
            {
                var xsdNo = Convert.ToInt32(httpReq.QueryString["xsd"]);
                var schemaSet = XsdUtils.GetXmlSchemaSet(operations.AllOperations.Types);
                var schemas = schemaSet.Schemas();
                var i = 0;
                if (xsdNo >= schemas.Count)
                {
                    throw new ArgumentOutOfRangeException("xsd");
                }
                httpRes.ContentType = "text/xml";
                foreach (XmlSchema schema in schemaSet.Schemas())
                {
                    if (xsdNo != i++) continue;
                    schema.Write(httpRes.Output);
                    break;
                }
                return;
            }

            var writer = new HtmlTextWriter(httpRes.Output);
            httpRes.ContentType = "text/html";
            ProcessOperations(writer, httpReq);
            writer.Flush();
        }
开发者ID:nigthwatch,项目名称:ServiceStack,代码行数:31,代码来源:BaseSoapMetadataHandler.cs


示例3: GetResponse

        public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
        {
            var requestContentType = ContentType.GetEndpointAttributes(httpReq.ResponseContentType);

            return ExecuteService(request,
                HandlerAttributes | requestContentType | GetEndpointAttributes(httpReq), httpReq, httpRes);
        }
开发者ID:vIceBerg,项目名称:ServiceStack,代码行数:7,代码来源:RestHandler.cs


示例4: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            var isDebugRequest = httpReq.RawUrl.ToLower().Contains("debug");
            if (!isDebugRequest)
            {
                base.ProcessRequest(httpReq, httpRes, operationName);
                return;
            }

            try
            {
                var request = CreateRequest(httpReq, operationName);

                var response = ExecuteService(request,
                    HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);

                WriteDebugResponse(httpRes, response);
            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);

                httpRes.WriteErrorToResponse(EndpointAttributes.Jsv, operationName, errorMessage, ex);
            }
        }
开发者ID:nigthwatch,项目名称:ServiceStack,代码行数:25,代码来源:JsvSyncReplyHandler.cs


示例5: 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


示例6: 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


示例7: ProcessRequest

		public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
		{
			try
			{
                EndpointHost.Config.AssertFeatures(format);

                if (EndpointHost.ApplyPreRequestFilters(httpReq, httpRes)) return;

				httpReq.ResponseContentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
				var callback = httpReq.QueryString["callback"];
				var doJsonp = EndpointHost.Config.AllowJsonpRequests
							  && !string.IsNullOrEmpty(callback);

				var request = CreateRequest(httpReq, operationName);
				if (EndpointHost.ApplyRequestFilters(httpReq, httpRes, request)) return;

				var response = GetResponse(httpReq, httpRes, request);
				if (EndpointHost.ApplyResponseFilters(httpReq, httpRes, response)) return;

				if (doJsonp && !(response is CompressedResult))
					httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
				else
					httpRes.WriteToResponse(httpReq, response);
			}
			catch (Exception ex)
			{
				if (!EndpointHost.Config.WriteErrorsToResponse) throw;
				HandleException(httpReq, httpRes, operationName, ex);
			}
		}
开发者ID:ELHANAFI,项目名称:ServiceStack,代码行数:30,代码来源:GenericHandler.cs


示例8: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            try
            {
                var contentType = httpReq.GetQueryStringContentType() ?? this.HandlerContentType;
                var callback = httpReq.QueryString["callback"];
                var doJsonp = EndpointHost.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                var request = CreateRequest(httpReq, operationName);

                var response = GetResponse(httpReq, request);

                var serializer = GetStreamSerializer(contentType);

                if (doJsonp) httpRes.Write(callback + "(");

                httpRes.WriteToResponse(response, serializer, contentType);

                if (doJsonp) httpRes.Write(")");

            }
            catch (Exception ex)
            {
                var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);
                Log.Error(errorMessage, ex);

                httpRes.WriteErrorToResponse(HandlerContentType, operationName, errorMessage, ex);
            }
        }
开发者ID:firstsee,项目名称:ServiceStack,代码行数:30,代码来源:GenericHandler.cs


示例9: Process

        public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            if (_ignoredPaths.Contains(request.Uri.AbsolutePath))
                return true;

            TextWriter writer = new StreamWriter(response.Body);

            try
            {
                string fileContents = File.ReadAllText("resources" + request.Uri.AbsolutePath);
                writer.Write(fileContents);
            }
            catch (Exception ex)
            {
                response.ContentType = "text/plain; charset=UTF-8";
                writer.WriteLine(ex.Message);
                writer.WriteLine(ex.StackTrace);
            }
            finally
            {
                writer.Flush();
            }

            return true;
        }
开发者ID:caelum,项目名称:NET-Selenium-DSL,代码行数:25,代码来源:FileReaderModule.cs


示例10: WriteToOutputStream

		public static bool WriteToOutputStream(IHttpResponse response, object result)
		{
			//var responseStream = response.OutputStream;

			var streamWriter = result as IStreamWriter;
			if (streamWriter != null)
			{
				streamWriter.WriteTo(response.OutputStream);
				return true;
			}

			var stream = result as Stream;
			if (stream != null)
			{
				stream.WriteTo(response.OutputStream);
				return true;
			}

			var bytes = result as byte[];
			if (bytes != null)
			{
				response.ContentType = ContentType.Binary;
				response.OutputStream.Write(bytes, 0, bytes.Length);
				return true;
			}

			return false;
		}
开发者ID:jonie,项目名称:ServiceStack,代码行数:28,代码来源:IHttpResponseExtensions.cs


示例11: ApplyResponseBodyFilter

        public byte[] ApplyResponseBodyFilter(IHttpResponse response, byte[] body, IEnumerable<Func<IHttpResponse, string, byte[], byte[]>> bodyCallbacks)
        {
            Contract.Requires(response != null);
            Contract.Requires(bodyCallbacks != null);

            return null;
        }
开发者ID:williamoneill,项目名称:Gallatin,代码行数:7,代码来源:IHttpResponseFilter.cs


示例12: ProcessRequest

        /// <summary>Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="T:System.Web.IHttpHandler" /> interface.</summary>
        ///
        /// <param name="request">      The request.</param>
        /// <param name="response">     The response.</param>
        /// <param name="operationName">Name of the operation.</param>
        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            response.ContentType = "text/plain";
            response.StatusCode = 403;

		    response.EndHttpHandlerRequest(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 (!NServiceKitHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
                    r.Write("\nApp.DebugLastHandlerArgs: " + NServiceKitHttpHandlerFactory.DebugLastHandlerArgs);
            });
		}
开发者ID:Qasemt,项目名称:NServiceKit,代码行数:34,代码来源:ForbiddenHttpHandler.cs


示例13: Replay

        public Task Replay(IHttpResponse response)
        {
            _writes.Each(x => x(response));


            return Task.CompletedTask;
        }
开发者ID:DarthFubuMVC,项目名称:fubumvc,代码行数:7,代码来源:WriteFileRecord.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;
            }

            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:niemyjski,项目名称:ServiceStack,代码行数:30,代码来源:AuthenticateAttribute.cs


示例15: 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


示例16: reactFire

 private void reactFire(IHttpResponse resp)
 {
     Console.WriteLine("Fire!");
     usbToys.FireMissile();
     resp.Status = System.Net.HttpStatusCode.OK;
     close(resp, "Fire!");
 }
开发者ID:drewbuschhorn,项目名称:STRIKER-II---C--Webserver,代码行数:7,代码来源:Program.cs


示例17: CouchServerResponse

        internal CouchServerResponse(IHttpResponse response)
        {
            try
            {
                var resp = JsonConvert.DeserializeObject<CouchServerResponseDefinition>(response.Data, CouchService.JsonSettings);

                Id = resp.Id;
                Revision = resp.Revision;

                if(resp.IsOk.HasValue)
                {
                    IsOk = resp.IsOk.Value;
                }
                else
                {
                    IsOk = response.StatusCode == HttpStatusCode.Created;
                }

                ErrorType = resp.Error;
                ErrorMessage = resp.Reason;
            }

            catch(Exception ex)
            {
                if (ex is JsonReaderException)
                {
                    IsOk = false;
                    ErrorType = "CouchNet Deserialization Error";
                    ErrorMessage = "Failed to deserialize server response (" + response.Data + ") Extra Info : " + ex.Message;
                }
            }
        }
开发者ID:emargee,项目名称:CouchNet,代码行数:32,代码来源:CouchServerResponse.cs


示例18: reactLaser

 private void reactLaser(IHttpResponse resp)
 {
     Console.WriteLine("Laser!");
     usbToys.ToggleLaser();
     resp.Status = System.Net.HttpStatusCode.OK;
     close(resp, "Laser!");
 }
开发者ID:drewbuschhorn,项目名称:STRIKER-II---C--Webserver,代码行数:7,代码来源:Program.cs


示例19: GetResponse

		public override object GetResponse(IHttpRequest httpReq, IHttpResponse httpRes, object request)
		{
			var response = ExecuteService(request,
                HandlerAttributes | httpReq.GetAttributes(), httpReq, httpRes);
			
			return response;
		}
开发者ID:ELHANAFI,项目名称:ServiceStack,代码行数:7,代码来源:GenericHandler.cs


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# IHttpRoute类代码示例发布时间:2022-05-24
下一篇:
C# IHttpRequest类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap