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

C# IHttpRequest类代码示例

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

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



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

示例1: RequestFilter

        public static void RequestFilter(IHttpRequest req, IHttpResponse res, object requestDto)
        {
            var validator = ValidatorCache.GetValidator(req, requestDto.GetType());
            if (validator == null) return;

            var validatorWithHttpRequest = validator as IRequiresHttpRequest;
            if (validatorWithHttpRequest != null)
                validatorWithHttpRequest.HttpRequest = req;

            var ruleSet = req.HttpMethod;
            var validationResult = validator.Validate(
                new ValidationContext(requestDto, null, new MultiRuleSetValidatorSelector(ruleSet)));

            if (validationResult.IsValid) return;

            var errorResponse = DtoUtils.CreateErrorResponse(
                requestDto, validationResult.ToErrorResult());

            var validationFeature = EndpointHost.GetPlugin<ValidationFeature>();
            if (validationFeature != null && validationFeature.ErrorResponseFilter != null)
            {
                errorResponse = validationFeature.ErrorResponseFilter(validationResult, errorResponse);
            }

            res.WriteToResponse(req, errorResponse);
        }
开发者ID:JonCanning,项目名称:ServiceStack,代码行数:26,代码来源:ValidationFilters.cs


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


示例3: DeserializeHttpRequest

        public static object DeserializeHttpRequest(Type operationType, IHttpRequest httpReq, string contentType)
        {
            var httpMethod = httpReq.HttpMethod;
            var queryString = httpReq.QueryString;

            if (httpMethod == HttpMethods.Get || httpMethod == HttpMethods.Delete || httpMethod == HttpMethods.Options)
            {
                try
                {
                    return KeyValueDataContractDeserializer.Instance.Parse(queryString, operationType);
                }
                catch (Exception ex)
                {
                    var msg = "Could not deserialize '{0}' request using KeyValueDataContractDeserializer: '{1}'.\nError: '{2}'"
                        .Fmt(operationType, queryString, ex);
                    throw new SerializationException(msg);
                }
            }

            var isFormData = httpReq.HasAnyOfContentTypes(ContentType.FormUrlEncoded, ContentType.MultiPartFormData);
            if (isFormData)
            {
                try
                {
                    return KeyValueDataContractDeserializer.Instance.Parse(httpReq.FormData, operationType);
                }
                catch (Exception ex)
                {
                    throw new SerializationException("Error deserializing FormData: " + httpReq.FormData, ex);
                }
            }

            var request = CreateContentTypeRequest(httpReq, operationType, contentType);
            return request;
        }
开发者ID:rossbeehler,项目名称:ServiceStack,代码行数:35,代码来源:EndpointHandlerBase.cs


示例4: SimplePreRequestFilter

 private void SimplePreRequestFilter(IHttpRequest req, IHttpResponse res)
 {
     if (Path.GetFileName(req.PathInfo).StartsWith("_"))
     {
         throw new HttpException("Files with leading underscores ('_') cannot be served.");
     }
 }
开发者ID:KennyBu,项目名称:ServiceStack,代码行数:7,代码来源:HelloAppHost.cs


示例5: ProcessRequest

        public void ProcessRequest(IHttpRequest request, IHttpResponse response, string operationName)
        {
            response.ContentType = "text/plain";
            response.StatusCode = 403;
            response.Write("Forbidden\n\n");

            response.Write("\nRequest.HttpMethod: " + request.HttpMethod);
            response.Write("\nRequest.PathInfo: " + request.PathInfo);
            response.Write("\nRequest.QueryString: " + request.QueryString);
            response.Write("\nRequest.RawUrl: " + request.RawUrl);

            if (IsIntegratedPipeline.HasValue)
                response.Write("\nApp.IsIntegratedPipeline: " + IsIntegratedPipeline);
            if (!WebHostPhysicalPath.IsNullOrEmpty())
                response.Write("\nApp.WebHostPhysicalPath: " + WebHostPhysicalPath);
            if (!WebHostRootFileNames.IsEmpty())
                response.Write("\nApp.WebHostRootFileNames: " + TypeSerializer.SerializeToString(WebHostRootFileNames));
            if (!ApplicationBaseUrl.IsNullOrEmpty())
                response.Write("\nApp.ApplicationBaseUrl: " + ApplicationBaseUrl);
            if (!DefaultRootFileName.IsNullOrEmpty())
                response.Write("\nApp.DefaultRootFileName: " + DefaultRootFileName);
            if (!DefaultHandler.IsNullOrEmpty())
                response.Write("\nApp.DefaultHandler: " + DefaultHandler);
            if (!ServiceStackHttpHandlerFactory.DebugLastHandlerArgs.IsNullOrEmpty())
                response.Write("\nApp.DebugLastHandlerArgs: " + ServiceStackHttpHandlerFactory.DebugLastHandlerArgs);

            ServiceStack.WebHost.Endpoints.EndpointHost.AddGlobalResponseHeaders(response);
            //Apache+mod_mono doesn't like this
            //response.OutputStream.Flush();
            //response.Close();
        }
开发者ID:assaframan,项目名称:ServiceStack,代码行数:31,代码来源:ForbiddenHttpHandler.cs


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


示例7: WriteToResponse

        public static bool WriteToResponse(this IHttpResponse httpRes, IHttpRequest httpReq, object result, byte[] bodyPrefix, byte[] bodySuffix)
        {
            if (result == null)
            {
                httpRes.EndHttpRequestWithNoContent();
                return true;
            }

            var serializationContext = new HttpRequestContext(httpReq, httpRes, result);
            var httpResult = result as IHttpResult;
            if (httpResult != null)
            {
                if (httpResult.ResponseFilter == null)
                {
                    httpResult.ResponseFilter = EndpointHost.AppHost.ContentTypeFilters;
                }
                httpResult.RequestContext = serializationContext;
                serializationContext.ResponseContentType = httpResult.ContentType ?? httpReq.ResponseContentType;
                var httpResSerializer = httpResult.ResponseFilter.GetResponseSerializer(serializationContext.ResponseContentType);
                return httpRes.WriteToResponse(httpResult, httpResSerializer, serializationContext, bodyPrefix, bodySuffix);
            }

            var serializer = EndpointHost.AppHost.ContentTypeFilters.GetResponseSerializer(httpReq.ResponseContentType);
            return httpRes.WriteToResponse(result, serializer, serializationContext, bodyPrefix, bodySuffix);
        }
开发者ID:h2oman,项目名称:ServiceStack,代码行数:25,代码来源:IHttpResponseExtensions.cs


示例8: CreateTemporarySessionId

 public static string CreateTemporarySessionId(this IHttpResponse res, IHttpRequest req)
 {
     var sessionId = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
     res.Cookies.AddSessionCookie(SessionFeature.SessionId, sessionId);
     req.Items[SessionFeature.SessionId] = sessionId;
     return sessionId;
 }
开发者ID:ceesalberts,项目名称:ServiceStack,代码行数:7,代码来源:SessionExtensions.cs


示例9: GetQueryValue

 public static string GetQueryValue(IHttpRequest req, string name)
 {
     string value;
     if (req.QueryData.TryGetValue (name, out value))
         return value;
     return string.Empty;
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:7,代码来源:Helpers.cs


示例10: GetResponse

        public override object GetResponse(IHttpRequest httpReq, object request)
        {
            var response = ExecuteService(request,
                HandlerAttributes | GetEndpointAttributes(httpReq), httpReq);

            return response;
        }
开发者ID:NokNokLLC,项目名称:ServiceStack,代码行数:7,代码来源:GenericHandler.cs


示例11: CreateSessionId

 /// <summary>
 /// Create the active Session or Permanent Session Id cookie.
 /// </summary>
 /// <returns></returns>
 public static string CreateSessionId(this IHttpResponse res, IHttpRequest req)
 {
     var sessionOptions = GetSessionOptions(req);
     return sessionOptions.Contains(SessionOptions.Permanent)
         ? res.CreatePermanentSessionId(req)
         : res.CreateTemporarySessionId(req);
 }
开发者ID:ceesalberts,项目名称:ServiceStack,代码行数:11,代码来源:SessionExtensions.cs


示例12: GetRequest

        public object GetRequest(IHttpRequest httpReq, string operationName)
        {
            var operationType = GetOperationType(operationName);
            AssertOperationExists(operationName, operationType);

            return DeserializeContentType(operationType, httpReq, HandlerContentType);
        }
开发者ID:NokNokLLC,项目名称:ServiceStack,代码行数:7,代码来源:GenericHandler.cs


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


示例14: ExecuteSync

        /// <summary>
        /// 同步的请求方式
        /// </summary>
        /// <param name="request">请求的参数</param>
        /// <returns>自定义的Response结果</returns>
        public IHttpResponse ExecuteSync(IHttpRequest request)
        {
            IHttpResponse response = new HttpResponse();
            try
            {
                if (string.IsNullOrEmpty(request.AddressUrl)
                    || request.HttpMothed == HttpMothed.None)
                {
                    response.ResponseStatus = ResponseStatus.Error;
                    response.ErrorException = new Exception("对不起,请求出错,请检查参数等设置(地址,请求方式等)!");
                    return response;
                }
                HttpWebRequest webrequest = ConfigureWebRequest(request);

                SendBodyDataSync(webrequest, request);

                GetResponse(webrequest, ref response);
            }
            catch (Exception ex)
            {
                response.ErrorException = ex;
                response.ResponseStatus = ResponseStatus.Error;
            }
            return response;
        }
开发者ID:rainchan,项目名称:weitao,代码行数:30,代码来源:RestHttp.Sync.cs


示例15: RenderOperation

        protected override void RenderOperation(System.Web.UI.HtmlTextWriter writer, IHttpRequest httpReq, string operationName, string requestMessage, string responseMessage, string metadataHtml)
        {
            var operationControl = new Soap12OperationControl
            {
                HttpRequest = httpReq,
                MetadataConfig = EndpointHost.Config.ServiceEndpointsMetadataConfig,
                Title = EndpointHost.Config.ServiceName,
                Format = this.Format,
                OperationName = operationName,
                HostName = httpReq.GetUrlHostName(),
                RequestMessage = requestMessage,
                ResponseMessage = responseMessage,
                MetadataHtml = metadataHtml,
            };
            if (!this.ContentType.IsNullOrEmpty())
            {
                operationControl.ContentType = this.ContentType;
            }
            if (!this.ContentFormat.IsNullOrEmpty())
            {
                operationControl.ContentFormat = this.ContentFormat;
            }

            operationControl.Render(writer);
        }
开发者ID:KennyBu,项目名称:ServiceStack,代码行数:25,代码来源:Soap12MetadataHandler.cs


示例16: PollServiceHttpRequest

 public PollServiceHttpRequest(PollServiceEventArgs pPollServiceArgs, IHttpClientContext pHttpContext, IHttpRequest pRequest)
 {
     PollServiceArgs = pPollServiceArgs;
     HttpContext = pHttpContext;
     Request = pRequest;
     RequestTime = System.Environment.TickCount;
 }
开发者ID:ChrisD,项目名称:opensim,代码行数:7,代码来源:PollServiceHttpRequest.cs


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


示例18: Get

        public static Response<Servicio> Get(this Servicio request,
		                                              Factory factory,
		                                              IHttpRequest httpRequest)
        {
            return factory.Execute(proxy=>{

				long? totalCount=null;

				var paginador= new Paginador(httpRequest);
            	
                var predicate = PredicateBuilder.True<Servicio>();

                var visitor = ReadExtensions.CreateExpression<Servicio>();

				if(!request.Nombre.IsNullOrEmpty()){
					predicate = predicate.AndAlso(q=> q.Nombre.Contains(request.Nombre));
				}

				visitor.Where(predicate).OrderBy(f=>f.Nombre);
                if(paginador.PageNumber.HasValue)
                {
					visitor.Select(r=> Sql.Count(r.Id));
					totalCount= proxy.Count(visitor);
					visitor.Select();
                    int rows= paginador.PageSize.HasValue? paginador.PageSize.Value:BL.ResponsePageSize;
                    visitor.Limit(paginador.PageNumber.Value*rows, rows);
                }
                
				return new Response<Servicio>(){
                	Data=proxy.Get(visitor),
                	TotalCount=totalCount
            	};
            });
  
        }
开发者ID:angelcolmenares,项目名称:Aicl.Delfin,代码行数:35,代码来源:BL.Servicio.cs


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


示例20: ProcessRequest

        public override void ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, string operationName)
        {
            httpRes.ContentType = MimeTypes.Html;
            if (RazorFormat == null)
                RazorFormat = RazorFormat.Instance;

            var contentPage = RazorPage ?? RazorFormat.FindByPathInfo(PathInfo);
            if (contentPage == null)
            {
                httpRes.StatusCode = (int)HttpStatusCode.NotFound;
                httpRes.EndHttpHandlerRequest();
                return;
            }

            var model = Model;
            if (model == null)
                httpReq.Items.TryGetValue("Model", out model);
            if (model == null)
            {
                var modelType = RazorPage != null ? RazorPage.ModelType : null;
                model = modelType == null || modelType == typeof(DynamicRequestObject)
                    ? null
                    : DeserializeHttpRequest(modelType, httpReq, httpReq.ContentType);
            }

            RazorFormat.ProcessRazorPage(httpReq, contentPage, model, httpRes);
        }
开发者ID:ELHANAFI,项目名称:ServiceStack,代码行数:27,代码来源:RazorHandler.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# IHttpResponse类代码示例发布时间:2022-05-24
下一篇:
C# IHttpProvider类代码示例发布时间: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