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


C# IRequest.SetRoute方法代码示例

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


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

示例1: ProcessRequestAsync

        public override Task ProcessRequestAsync(IRequest httpReq, IResponse httpRes, string operationName)
        {
            try
            {
                var appHost = HostContext.AppHost;
                if (appHost.ApplyPreRequestFilters(httpReq, httpRes)) 
                    return EmptyTask;
                
                var restPath = GetRestPath(httpReq.Verb, httpReq.PathInfo);
                if (restPath == null)
                {
                    return new NotSupportedException("No RestPath found for: " + httpReq.Verb + " " + httpReq.PathInfo)
                        .AsTaskException();
                }
                httpReq.SetRoute(restPath as RestPath);

                operationName = restPath.RequestType.GetOperationName();

                var callback = httpReq.GetJsonpCallback();
                var doJsonp = HostContext.Config.AllowJsonpRequests
                              && !string.IsNullOrEmpty(callback);

                if (ResponseContentType != null)
                    httpReq.ResponseContentType = ResponseContentType;

                var responseContentType = httpReq.ResponseContentType;
                appHost.AssertContentType(responseContentType);

                var request = httpReq.Dto = CreateRequest(httpReq, restPath);

                if (appHost.ApplyRequestFilters(httpReq, httpRes, request)) 
                    return EmptyTask;

                var rawResponse = GetResponse(httpReq, request);
                return HandleResponse(rawResponse, response => 
                {
                    response = appHost.ApplyResponseConverters(httpReq, response);

                    if (appHost.ApplyResponseFilters(httpReq, httpRes, response)) 
                        return EmptyTask;

                    if (responseContentType.Contains("jsv") && !string.IsNullOrEmpty(httpReq.QueryString[Keywords.Debug]))
                        return WriteDebugResponse(httpRes, response);

                    if (doJsonp && !(response is CompressedResult))
                        return httpRes.WriteToResponse(httpReq, response, (callback + "(").ToUtf8Bytes(), ")".ToUtf8Bytes());
                    
                    return httpRes.WriteToResponse(httpReq, response);
                },  
                ex => !HostContext.Config.WriteErrorsToResponse 
                    ? ex.ApplyResponseConverters(httpReq).AsTaskException()
                    : HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq)));
            }
            catch (Exception ex)
            {
                return !HostContext.Config.WriteErrorsToResponse
                    ? ex.ApplyResponseConverters(httpReq).AsTaskException()
                    : HandleException(httpReq, httpRes, operationName, ex.ApplyResponseConverters(httpReq));
            }
        }
开发者ID:dittodhole,项目名称:dotnet-ServiceStack,代码行数:60,代码来源:RestHandler.cs

示例2: Execute

        public object Execute(IRequest req, bool applyFilters)
        {
            string contentType;
            var restPath = RestHandler.FindMatchingRestPath(req.Verb, req.PathInfo, out contentType);
            req.SetRoute(restPath as RestPath);
            req.OperationName = restPath.RequestType.GetOperationName();
            var requestDto = RestHandler.CreateRequest(req, restPath);
            req.Dto = requestDto;

            if (applyFilters)
            {
                if (appHost.ApplyRequestFilters(req, req.Response, requestDto))
                    return null;
            }

            var response = Execute(requestDto, req);

            return applyFilters 
                ? ApplyResponseFilters(response, req) 
                : response;
        }
开发者ID:yuinlin,项目名称:ServiceStack,代码行数:21,代码来源:ServiceController.cs

示例3: Execute

        public object Execute(IRequest req)
        {
            string contentType;
            var restPath = RestHandler.FindMatchingRestPath(req.Verb, req.PathInfo, out contentType);
            req.SetRoute(restPath as RestPath);
            req.OperationName = restPath.RequestType.GetOperationName();
            var request = RestHandler.CreateRequest(req, restPath);
            req.Dto = request;

            if (appHost.ApplyRequestFilters(req, req.Response, request))
                return null;

            var response = appHost.ApplyResponseConverters(req, Execute(request, req));

            if (appHost.ApplyResponseFilters(req, req.Response, response))
                return null;

            return response;
        }
开发者ID:quyenbc,项目名称:ServiceStack,代码行数:19,代码来源:ServiceController.cs


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