本文整理汇总了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;
}
示例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);
}
}
}