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


C# Controllers.HttpRequestContext类代码示例

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


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

示例1: TryHandle

        public async Task<HttpResponseMessage> TryHandle(HttpRequestMessage request, Func<HttpRequestMessage, Task<HttpResponseMessage>> invokeJobFunction)
        {
            // First check if there is a registered WebHook Receiver for this request, and if
            // so use it
            string route = request.RequestUri.LocalPath.ToLowerInvariant();
            IWebHookReceiver receiver = null;
            string receiverId = null;

            if (TryParseReceiver(route, out receiver, out receiverId))
            {
                HttpRequestContext context = new HttpRequestContext
                {
                    Configuration = _httpConfiguration
                };
                request.SetConfiguration(_httpConfiguration);

                // add the anonymous handler function from above to the request properties
                // so our custom WebHookHandler can invoke it at the right time
                request.Properties.Add(WebHookJobFunctionInvokerKey, invokeJobFunction);

                return await receiver.ReceiveAsync(receiverId, context, request);
            }

            return null;
        }
开发者ID:paulbatum,项目名称:azure-webjobs-sdk-extensions,代码行数:25,代码来源:WebHookReceiverManager.cs

示例2: CreateHttpRequestMessage

        private static HttpRequestMessage CreateHttpRequestMessage(HttpActionDescriptor actionDescriptor, ODataRoute oDataRoute, HttpConfiguration httpConfig)
        {
            Contract.Requires(httpConfig != null);
            Contract.Requires(oDataRoute != null);
            Contract.Requires(httpConfig != null);
            Contract.Ensures(Contract.Result<HttpRequestMessage>() != null);

            Contract.Assume(oDataRoute.Constraints != null);

            var httpRequestMessage = new HttpRequestMessage(actionDescriptor.SupportedHttpMethods.First(), "http://any/");

            var requestContext = new HttpRequestContext
            {
                Configuration = httpConfig
            };
            httpRequestMessage.SetConfiguration(httpConfig);
            httpRequestMessage.SetRequestContext(requestContext);

            var httpRequestMessageProperties = httpRequestMessage.ODataProperties();
            Contract.Assume(httpRequestMessageProperties != null);
            httpRequestMessageProperties.Model = oDataRoute.GetEdmModel();
            httpRequestMessageProperties.RouteName = oDataRoute.GetODataPathRouteConstraint().RouteName;
            httpRequestMessageProperties.RoutingConventions = oDataRoute.GetODataPathRouteConstraint().RoutingConventions;
            httpRequestMessageProperties.PathHandler = oDataRoute.GetODataPathRouteConstraint().PathHandler;
            return httpRequestMessage;
        }
开发者ID:bigred8982,项目名称:Swashbuckle.OData,代码行数:26,代码来源:AttributeRouteStrategy.cs

示例3: AttributesController

 //Automation Constructor
 public AttributesController(IAttributesManager IAttributesManager, HttpRequestMessage Request, HttpRequestContext RequestContext)
 {
     parameters = new Dictionary<string, string>();
     this.RequestContext = RequestContext;
     this.Request = Request;
     this.AttributesManager = IAttributesManager;
 }
开发者ID:Pamplemousse09,项目名称:offerservice3,代码行数:8,代码来源:AttributesController.cs

示例4: HttpControllerContext

        /// <summary>Initializes a new instance of the <see cref="HttpControllerContext"/> class.</summary>
        /// <param name="requestContext">The request context.</param>
        /// <param name="request">The HTTP request.</param>
        /// <param name="controllerDescriptor">The controller descriptor.</param>
        /// <param name="controller">The controller.</param>
        public HttpControllerContext(HttpRequestContext requestContext, HttpRequestMessage request,
            HttpControllerDescriptor controllerDescriptor, IHttpController controller)
        {
            if (requestContext == null)
            {
                throw Error.ArgumentNull("requestContext");
            }

            if (request == null)
            {
                throw Error.ArgumentNull("request");
            }

            if (controllerDescriptor == null)
            {
                throw Error.ArgumentNull("controllerDescriptor");
            }

            if (controller == null)
            {
                throw Error.ArgumentNull("controller");
            }

            _requestContext = requestContext;
            _request = request;
            _controllerDescriptor = controllerDescriptor;
            _controller = controller;
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:33,代码来源:HttpControllerContext.cs

示例5: Register

        public Task Register(ApiServices services, HttpRequestContext context,
        NotificationRegistration registration)
        {
            try
            {
                // Perform a check here for user ID tags, which are not allowed.
                if (!ValidateTags(registration))
                {
                    throw new InvalidOperationException(
                        "You cannot supply a tag that is a user ID.");
                }

                // Get the logged-in user.
                var currentUser = context.Principal as ServiceUser;

                // Add a new tag that is the user ID.
                registration.Tags.Add(currentUser.Id);

                //services.Log.Info("Registered tag for userId: " + currentUser.Id);
            }
            catch (Exception ex)
            {
                //services.Log.Error(ex.ToString());
            }
            return Task.FromResult(true);
        }
开发者ID:Pointrest,项目名称:ialfvg_social_azure_mobiles_services,代码行数:26,代码来源:PushRegistrationHandler.cs

示例6: ReceiveAsync

        /// <inheritdoc />
        public override async Task<HttpResponseMessage> ReceiveAsync(string id, HttpRequestContext context, HttpRequestMessage request)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (request.Method == HttpMethod.Post)
            {
                // Ensure that we use https and have a valid code parameter
                await EnsureValidCode(request, id);

                // Read the request entity body.
                JObject data = await ReadAsJsonAsync(request);

                // Call registered handlers
                return await ExecuteWebHookAsync(id, context, request, new string[] { DefaultAction }, data);
            }
            else
            {
                return CreateBadMethodResponse(request);
            }
        }
开发者ID:aspnet,项目名称:WebHooks,代码行数:32,代码来源:ZendeskWebHookReceiver.cs

示例7: StripeWebHookReceiverTests

        public StripeWebHookReceiverTests()
        {
            _settings = new SettingsDictionary();
            _settings["MS_WebHookReceiverSecret_Stripe"] = TestSecret;

            _config = HttpConfigurationMock.Create(new Dictionary<Type, object> { { typeof(SettingsDictionary), _settings } });
            _context = new HttpRequestContext { Configuration = _config };

            _stripeResponse = new HttpResponseMessage();
            _stripeResponse.Content = new StringContent("{ \"type\": \"action\" }", Encoding.UTF8, "application/json");

            _handlerMock = new HttpMessageHandlerMock();
            _handlerMock.Handler = (req, counter) =>
            {
                string expected = string.Format(CultureInfo.InvariantCulture, StripeWebHookReceiver.EventUriTemplate, TestId);
                Assert.Equal(req.RequestUri.AbsoluteUri, expected);
                return Task.FromResult(_stripeResponse);
            };

            _httpClient = new HttpClient(_handlerMock);
            _receiverMock = new Mock<StripeWebHookReceiver>(_httpClient) { CallBase = true };

            _postRequest = new HttpRequestMessage { Method = HttpMethod.Post };
            _postRequest.SetRequestContext(_context);
        }
开发者ID:Joshzx,项目名称:WebHooks,代码行数:25,代码来源:StripeWebHookReceiverTests.cs

示例8: DropboxWebHookReceiverTests

        public DropboxWebHookReceiverTests()
        {
            _settings = new SettingsDictionary();
            _settings["MS_WebHookReceiverSecret_Dropbox"] = TestSecret;

            _config = HttpConfigurationMock.Create(new Dictionary<Type, object> { { typeof(SettingsDictionary), _settings } });
            _context = new HttpRequestContext { Configuration = _config };

            _receiverMock = new Mock<DropboxWebHookReceiver> { CallBase = true };

            _getRequest = new HttpRequestMessage();
            _getRequest.SetRequestContext(_context);

            _postRequest = new HttpRequestMessage() { Method = HttpMethod.Post };
            _postRequest.SetRequestContext(_context);
            _postRequest.Content = new StringContent(TestContent, Encoding.UTF8, "application/json");

            byte[] secret = Encoding.UTF8.GetBytes(TestSecret);
            using (var hasher = new HMACSHA256(secret))
            {
                byte[] data = Encoding.UTF8.GetBytes(TestContent);
                byte[] testHash = hasher.ComputeHash(data);
                _testSignature = EncodingUtilities.ToHex(testHash);
            }
        }
开发者ID:Joshzx,项目名称:WebHooks,代码行数:25,代码来源:DropboxWebHookReceiverTests.cs

示例9: HandleRequestAsync

        public async Task<HttpResponseMessage> HandleRequestAsync(FunctionDescriptor function, HttpRequestMessage request, Func<HttpRequestMessage, Task<HttpResponseMessage>> invokeFunction)
        {
            // First check if there is a registered WebHook Receiver for this request, and if
            // so use it
            HttpTriggerBindingMetadata httpFunctionMetadata = (HttpTriggerBindingMetadata)function.Metadata.InputBindings.FirstOrDefault(p => p.Type == BindingType.HttpTrigger);
            string webHookReceiver = httpFunctionMetadata.WebHookType;
            IWebHookReceiver receiver = null;
            if (string.IsNullOrEmpty(webHookReceiver) || !_receiverLookup.TryGetValue(webHookReceiver, out receiver))
            {
                // The function is not correctly configured. Log an error and return 500
                string configurationError = string.Format(CultureInfo.InvariantCulture, "Invalid WebHook configuration. Unable to find a receiver for WebHook type '{0}'", webHookReceiver);
                function.Invoker.OnError(new FunctionInvocationException(configurationError));

                return new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError);
            }

            HttpRequestContext context = new HttpRequestContext
            {
                Configuration = _httpConfiguration
            };
            request.SetConfiguration(_httpConfiguration);

            // add the anonymous handler function from above to the request properties
            // so our custom WebHookHandler can invoke it at the right time
            request.Properties.Add(AzureFunctionsCallbackKey, invokeFunction);

            // Request content can't be read multiple
            // times, so this forces it to buffer
            await request.Content.LoadIntoBufferAsync();

            string receiverId = function.Name.ToLowerInvariant();
            return await receiver.ReceiveAsync(receiverId, context, request);
        }
开发者ID:isaacabraham,项目名称:azure-webjobs-sdk-script,代码行数:33,代码来源:WebHookReceiverManager.cs

示例10: TrelloWebHookReceiverTests

        public TrelloWebHookReceiverTests()
        {
            _settings = new SettingsDictionary();
            _settings["MS_WebHookReceiverSecret_Trello"] = TestSecret;

            _config = HttpConfigurationMock.Create(new Dictionary<Type, object> { { typeof(SettingsDictionary), _settings } });
            _context = new HttpRequestContext { Configuration = _config };

            _receiverMock = new Mock<TrelloWebHookReceiver> { CallBase = true };

            _headRequest = new HttpRequestMessage() { Method = HttpMethod.Head };
            _headRequest.SetRequestContext(_context);

            _postRequest = new HttpRequestMessage(HttpMethod.Post, TestAddress);
            _postRequest.SetRequestContext(_context);
            _postRequest.Content = new StringContent(TestContent, Encoding.UTF8, "application/json");

            byte[] secret = Encoding.UTF8.GetBytes(TestSecret);
            using (var hasher = new HMACSHA1(secret))
            {
                byte[] data = Encoding.UTF8.GetBytes(TestContent);
                byte[] requestUri = Encoding.UTF8.GetBytes(TestAddress);
                byte[] combo = new byte[data.Length + requestUri.Length];
                Buffer.BlockCopy(data, 0, combo, 0, data.Length);
                Buffer.BlockCopy(requestUri, 0, combo, data.Length, requestUri.Length);
                byte[] testHash = hasher.ComputeHash(combo);
                _signature = EncodingUtilities.ToBase64(testHash, uriSafe: false);
            }
        }
开发者ID:Joshzx,项目名称:WebHooks,代码行数:29,代码来源:TrelloWebHookReceiverTests.cs

示例11: AddNavigationUrl

 public static void AddNavigationUrl(this IList<Map> maps, HttpRequestContext context)
 {
     foreach (var map in maps)
     {
         map.Href = string.Format("{0}/{1}", context.Url.Request.RequestUri.AbsoluteUri, map.Id);
     }
 }
开发者ID:jgguevara,项目名称:IPS.Administration,代码行数:7,代码来源:MapExtension.cs

示例12: ReceiveAsync

        /// <inheritdoc />
        public override async Task<HttpResponseMessage> ReceiveAsync(string id, HttpRequestContext context, HttpRequestMessage request)
        {
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }
            if (request.Method != HttpMethod.Post)
            {
                return CreateBadMethodResponse(request);
            }

            // Ensure that the request was made with HTTPS and contains a valid `code` parameter.
            await EnsureValidCode(request, id);

            // Read the request entity body.
            JObject data = await ReadAsJsonAsync(request);
            string messageName = data != null ? data.Value<string>("MessageName") : string.Empty;

            // Call registered WebHook handlers.
            return await ExecuteWebHookAsync(id, context, request, new string[] { messageName }, data);
        }
开发者ID:brianweet,项目名称:WebHooks,代码行数:30,代码来源:DynamicsCrmWebHookReceiver.cs

示例13: ApiInfo

        public ApiInfo ApiInfo(HttpRequestContext request)
        {
            var k = request.Url.Request;

            var urlRoot = UrlRoot(request.Url.Request);
            return new ApiInfo
            {
                Title = "CalRecycle Used Oil LCA API",
                Maintainer = new Contact
                {
                    Name = "Brandon Kuczenski",
                    Email = "[email protected]"
                },
                Version = ServicesVersion(),
                Links = new List<Link>
                {
                    HelpLink(urlRoot),
                    new Link () {
                        Rel = "license",
                        Title = "BSD License",
                        Href = urlRoot + "LICENSE"
                    }
                }
            };
        }
开发者ID:uo-lca,项目名称:CalRecycleLCA,代码行数:25,代码来源:DocuService.cs

示例14: AddNavigationUrl

 public static void AddNavigationUrl(this IList<PointOfInterest> pois, HttpRequestContext context)
 {
     foreach (var poi in pois)
     {
         poi.Href = string.Format("{0}/pois/{1}", context.Url.Request.RequestUri.AbsoluteUri, poi.Id);
     }
 }
开发者ID:jgguevara,项目名称:IPS.Administration,代码行数:7,代码来源:PoIExtension.cs

示例15: ApiControllerExtensionsTests

        public ApiControllerExtensionsTests()
        {
            HttpConfiguration config = new HttpConfiguration();
            IWebHookUser user = new WebHookUser();

            _managerMock = new Mock<IWebHookManager>();
            _resolverMock = new Mock<IDependencyResolver>();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookManager)))
                .Returns(_managerMock.Object)
                .Verifiable();
            _resolverMock.Setup(r => r.GetService(typeof(IWebHookUser)))
                .Returns(user)
                .Verifiable();

            config.DependencyResolver = _resolverMock.Object;

            ClaimsIdentity identity = new ClaimsIdentity();
            Claim claim = new Claim(ClaimTypes.Name, "TestUser");
            identity.AddClaim(claim);
            _principal = new ClaimsPrincipal(identity);

            _context = new HttpRequestContext()
            {
                Configuration = config,
                Principal = _principal
            };
            _controller = new TestController()
            {
                RequestContext = _context
            };
        }
开发者ID:Joshzx,项目名称:WebHooks,代码行数:31,代码来源:ApiControllerExtensionsTests.cs


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