2013-08-28 94 views
1

我正在编写一个程序,其中包含由Visual Studio 2012提供的webBrowser控件。现在我想要获取webBrowser的版本。我发现MSDN代码示例:未列在Visual Studio 2012中的Request.Browser

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; 
+0

您正在使用的WinForms,的Request.Browser仅在网页enviroments – Gonzix

+0

呵呵,还好用。所以我不能以这种方式获得版本? – Roman

+0

你不能在winforms中。 winforms webbrowser控件只是将你的ie包裹在你的系统中。更改为mvc或webforms应用程序,您将能够执行该代码 – Gonzix

回答

2

正如您在MSDN link中所看到的,您所谈论的是在System.Web命名空间中请求。 Request通常以System.Web.HttpContext.Current.RequestPage(ASP.Net WebForms)或Controller(ASP.Net MVC)的属性提供。

但它不会帮助你在你的WinForms情景......

+0

谢谢你的家伙! – Roman

0

请尝试以下,如果你是在网络环境:

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

感谢您的回答:) – Roman