Request.Browser not listed by Visual Studio 2012

本文关键字:Visual Studio 2012 by listed Browser not Request | 更新日期: 2023-09-27 18:29:21

我正在编写一个程序,其中包含Visual Studio 2012提供的webBrowser控件。现在我想获得网络浏览器的版本。我发现了MSDN的一个代码示例:

HttpBrowserCapabilities bc = Request.Browser;
Response.Write("<p>Browser Capabilities:</p>");
Response.Write("Type = " + bc.Type + "<br>");
Response.Write("Name = " + bc.Browser + "<br>");
Response.Write("Version = " + bc.Version + "<br>");
Response.Write("Major Version = " + bc.MajorVersion + "<br>");
Response.Write("Minor Version = " + bc.MinorVersion + "<br>");
Response.Write("Platform = " + bc.Platform + "<br>");
Response.Write("Is Beta = " + bc.Beta + "<br>");
Response.Write("Is Crawler = " + bc.Crawler + "<br>");
Response.Write("Is AOL = " + bc.AOL + "<br>");
Response.Write("Is Win16 = " + bc.Win16 + "<br>");
Response.Write("Is Win32 = " + bc.Win32 + "<br>");
Response.Write("Supports Frames = " + bc.Frames + "<br>");
Response.Write("Supports Tables = " + bc.Tables + "<br>");
Response.Write("Supports Cookies = " + bc.Cookies + "<br>");
Response.Write("Supports VB Script = " + bc.VBScript + "<br>");
Response.Write("Supports JavaScript = " + bc.JavaScript + "<br>");
Response.Write("Supports Java Applets = " + bc.JavaApplets + "<br>");
Response.Write("Supports ActiveX Controls = " + bc.ActiveXControls + "<br>");
Response.Write("CDF = " + bc.CDF + "<br>");

但我现在的问题是:我找不到Request.Browser。它没有被VS2012列出。我试图添加一些.dll引用,但它仍然不起作用。我希望有人能给我一个有用的提示,告诉我应该去哪里看:)

干杯

编辑:我已经得到:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Web;
using System.Web.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Net.Http;
using System.Net;

Request.Browser not listed by Visual Studio 2012

正如您在MSDN链接中看到的,您所说的Request在System.Web命名空间中。Request通常可用作System.Web.HttpContext.Current.RequestPage(ASP.Net WebForms)或Controller(ASP.NetMVC)的属性。

但这对你的WinForms场景没有帮助。。。

如果您在web环境中,请尝试以下操作:

HttpRequest request;
string browser = request.Browser.Browser;