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


C# HttpRequestBase.ClientIPFromRequest方法代码示例

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


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

示例1: TrackPageView

        public static void TrackPageView(HttpRequestBase request, Config config, string title)
        {
            // Handle Piwik Tracking if enabled
            if (config.PiwikConfig.Enabled)
            {
                try
                {
                    // Follow Do Not Track
                    string doNotTrack = request.Headers["DNT"];
                    if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
                    {
                        string sub = request.RequestContext.RouteData.Values["sub"].ToString();
                        if (string.IsNullOrEmpty(sub))
                        {
                            sub = request.Url.AbsoluteUri.GetSubdomain();
                        }
                        if (config.DevEnvironment)
                        {
                            sub = "dev - " + sub;
                        }

                        PiwikTracker.URL = config.PiwikConfig.Url;
                        PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);

                        // Get Request Info
                        string ipAddress = request.ClientIPFromRequest(true);
                        tracker.setIp(ipAddress);
                        tracker.setTokenAuth(config.PiwikConfig.TokenAuth);
                        tracker.setUrl(request.Url.ToString());

                        tracker.setUserAgent(request.UserAgent);

                        // Get browser info
                        tracker.setResolution(request.Browser.ScreenPixelsWidth, request.Browser.ScreenPixelsHeight);
                        tracker.setBrowserHasCookies(request.Browser.Cookies);
                        if (!string.IsNullOrEmpty(request.Headers["Accept-Language"]))
                            tracker.setBrowserLanguage(request.Headers["Accept-Language"]);
                        BrowserPlugins plugins = new BrowserPlugins();
                        plugins.java = request.Browser.JavaApplets;
                        tracker.setPlugins(plugins);

                        // Get Referral
                        if (request.UrlReferrer != null)
                            tracker.setUrlReferrer(request.UrlReferrer.ToString());

                        // Send the tracking request
                        tracker.doTrackPageView(string.Format("{0}/{1}", sub, title));
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
开发者ID:Teknikode,项目名称:Teknik,代码行数:55,代码来源:Tracking.cs

示例2: TrackAction

        private static void TrackAction(HttpRequestBase request, Config config, string url, PiwikTracker.ActionType type)
        {
            // Handle Piwik Tracking if enabled
            if (config.PiwikConfig.Enabled)
            {
                try
                {
                    // Follow Do Not Track
                    string doNotTrack = request.Headers["DNT"];
                    if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
                    {
                        PiwikTracker.URL = config.PiwikConfig.Url;
                        PiwikTracker tracker = new PiwikTracker(config.PiwikConfig.SiteId);

                        tracker.setUserAgent(request.UserAgent);

                        string ipAddress = request.ClientIPFromRequest(true);

                        tracker.setIp(ipAddress);
                        tracker.setTokenAuth(config.PiwikConfig.TokenAuth);

                        // Get Referral
                        if (request.UrlReferrer != null)
                            tracker.setUrlReferrer(request.UrlReferrer.ToString());

                        tracker.doTrackAction(url, type);
                    }
                }
                catch (Exception ex)
                {

                }
            }
        }
开发者ID:Teknikode,项目名称:Teknik,代码行数:34,代码来源:Tracking.cs


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