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


C# HttpRequest.GetUserAgent方法代码示例

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


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

示例1: ShouldShowPrerenderedPage

		private bool ShouldShowPrerenderedPage(HttpRequest request)
		{
			var userAgent = request.GetUserAgent();

#warning Not sure about this implemetation
			var referer = request.Headers.ContainsKey("Referer") ? request.Headers["Referer"] : string.Empty;

			var url = request.GetFullUrl();

#warning Not sure what this is supposed to do
			if (HasEscapedFragment(request))
			{
				return true;
			}


			if (userAgent.IsEmptyString())
			{
				return false;
			}

			if (!IsSearchRobot(userAgent))
			{
				return false;
			}

			if (IsInResources(url))
			{
				return false;
			}

			var whiteList = options.Whitelist;
			if (whiteList != null && !IsInWhiteList(url, whiteList))
			{
				return false;
			}

			var blacklist = options.Blacklist;
			if (blacklist != null && IsInBlackList(url, referer, blacklist))
			{
				return false;
			}

			return true;

		}
开发者ID:OndrejValenta,项目名称:prerender.io.mvc6,代码行数:46,代码来源:WebRequestHelper.cs

示例2: GetPrerenderedPageResponse

		private ResponseResult GetPrerenderedPageResponse(HttpRequest request)
		{
			var apiUrl = GetApiUrl(request);
			var webRequest = (HttpWebRequest)WebRequest.Create(apiUrl);
			webRequest.Method = "GET";
			webRequest.UserAgent = request.GetUserAgent();

			SetProxy(webRequest);
			SetNoCache(webRequest);

			// Add our key!
			if (options.Token.IsNotEmptyString())
			{
				webRequest.Headers.Add("X-Prerender-Token", options.Token);
			}

			try
			{
				// Get the web response and read content etc. if successful
				var webResponse = (HttpWebResponse)webRequest.GetResponse();

				using (var reader = new StreamReader(webResponse.GetResponseStream(), Encoding.UTF8))
				{
					return new ResponseResult(webResponse.StatusCode, reader.ReadToEnd(), webResponse.Headers);
				}
			}
			catch (WebException e)
			{
				// Handle response WebExceptions for invalid renders (404s, 504s etc.) - but we still want the content
				using (var reader = new StreamReader(e.Response.GetResponseStream(), Encoding.UTF8))
				{
					return new ResponseResult(((HttpWebResponse)e.Response).StatusCode, reader.ReadToEnd(), e.Response.Headers);
				}
			}
		}
开发者ID:OndrejValenta,项目名称:prerender.io.mvc6,代码行数:35,代码来源:WebRequestHelper.cs


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