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


C# HttpContext.GetUserIp方法代码示例

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


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

示例1: ProcessRequest

        private void ProcessRequest(HttpContext context)
        {
            var headers = ToDictionary(context.Request.Headers);
            string urlReferrer = headers.SafeGet("Referer");
            string url = context.Request.GetDisplayUrl();

            var logRequestBase = new LogRequestBase(
                userAgent: headers.SafeGet("User-Agent"),
                userHostAddress: context.GetUserIp(),
                requestId: context.GetLogRequestId(),
                url: (urlReferrer ?? url).ToString(),
                queryParameters: ToDictionary(context.Request.Query),
                cookies: ToDictionary(context.Request.Cookies),
                headers: headers);

            DateTime serverSideTimeUtc = DateTime.UtcNow;
            string httpMethod = context.Request.Method;
            string origin = headers.SafeGet("Origin");

            Encoding encoding = HttpHelpers.GetEncoding(headers.SafeGet("Content-Type"));

            string json;
            using (var reader = new StreamReader(context.Request.Body, encoding))
            {
                json = reader.ReadToEnd();
            }

            var response = new LogResponse();

            LoggerProcessor.ProcessLogRequest(json, logRequestBase,
                serverSideTimeUtc,
                httpMethod, origin, response);

            // Send dummy response. That way, the log request will not remain "pending"
            // in eg. Chrome dev tools.
            //
            // This must be given a MIME type of "text/plain"
            // Otherwise, the browser may try to interpret the empty string as XML.
            // When the user uses Firefox, and right clicks on the page and chooses "Inspect Element",
            // then in that debugger's console it will say "no element found".
            // See
            // http://www.acnenomor.com/307387p1/how-do-i-setup-my-ajax-post-request-to-prevent-no-element-found-on-empty-response
            // http://stackoverflow.com/questions/975929/firefox-error-no-element-found/976200#976200

            ToAspNet5Response(response, context.Response);
            context.Response.ContentType = "text/plain";
            context.Response.ContentLength = 0;
        }
开发者ID:mperdeck,项目名称:jsnlog,代码行数:48,代码来源:JSNLogMiddleware.cs


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