代码如下希望能帮到你
asp.net ua获取 <% string ua1 = Request.ServerVariables["HTTP_USER_AGENT"]; Response.Write(ua1); %>
asp.net referer Request.ServerVariables["HTTP_REFERER"]
你按F12开调试,看下不同的浏览器提交html头.看下头里面有些什么有用的数据.你能得到的所有东西,都在请求报文里
我现在用代码获取了,但是获取的值是空值。
代码如下:
string browserType = ctx.Request.Browser.Type;
string osName = GetOSNameByUserAgent(useragent);
string referer = ctx.Request.ServerVariables["http_referer"];
private string GetOSNameByUserAgent(string userAgent)
{
string osVersion = "未知";
if (userAgent.Contains("NT 6.0"))
{
osVersion = "Windows Vista/Server 2008";
}
else if (userAgent.Contains("NT 5.2"))
{
osVersion = "Windows Server 2003";
}
else if (userAgent.Contains("NT 5.1"))
{
osVersion = "Windows XP";
}
else if (userAgent.Contains("NT 5"))
{
osVersion = "Windows 2000";
}
else if (userAgent.Contains("NT 4"))
{
osVersion = "Windows NT4";
}
else if (userAgent.Contains("Me"))
{
osVersion = "Windows Me";
}
else if (userAgent.Contains("98"))
{
osVersion = "Windows 98";
}
else if (userAgent.Contains("95"))
{
osVersion = "Windows 95";
}
else if (userAgent.Contains("Mac"))
{
osVersion = "Mac";
}
else if (userAgent.Contains("Unix"))
{
osVersion = "UNIX";
}
else if (userAgent.Contains("Linux"))
{
osVersion = "Linux";
}
else if (userAgent.Contains("SunOS"))
{
osVersion = "SunOS";
}
return osVersion;
}