要读取标题值,您可以使用下面的代码。
我通过使用user-agent
它可以了解浏览器。
C#
var headers = Request.Headers.ToString();
// If you want it formated in some other way.
var headers = String.Empty;
foreach (var key in Request.Headers.AllKeys)
headers += key + "=" + Request.Headers[key] + Environment.NewLine;
VB.NET:
Dim headers = Request.Headers.ToString()
' If you want it formated in some other way.'
Dim headers As String = String.Empty
For Each key In Request.Headers.AllKeys
headers &= key & "=" & Request.Headers(key) & Environment.NewLine
Next
从在 ASP.NET (Android) 中检测移动设备用户代理:
//for Mobile device
protected override void OnInit(EventArgs e)
{
string userAgent = Request.UserAgent;
if (userAgent.Contains("BlackBerry")
|| (userAgent.Contains("iPhone") || (userAgent.Contains("Android"))))
{
//add css ref to header from code behind
HtmlLink css = new HtmlLink();
css.Href = ResolveClientUrl("~/mobile.css");
css.Attributes["rel"] = "stylesheet";
css.Attributes["type"] = "text/css";
css.Attributes["media"] = "all";
Page.Header.Controls.Add(css);
}
}