System.Web.HttpBrowserCapabilities browser = Request.Browser; 
            Label2.Text="您现在的浏览器版本为"+browser.Browser+""+browser.Version;

解决方案 »

  1.   

    to howbigsea(大海):
    我看不出你和我的做法差别在哪里?
      

  2.   

    感谢您使用微软产品。对于这种问题,建议您采取下面的方法来进行排错:1。 您可以在您的Page_Load事件中,加入下面的代码:this.Label1.Text=this.Request.ServerVariables[@"HTTP_USER_AGENT"];我们可以来检查该变量的值.2。 您可以在您的代码中加入下面的代码,把用户发送到浏览器端的请求保存到文本文件:this.Request.SaveAs(@"c:\MyLog\test.txt",true);请您确认在您的机器上面ASPNET账号拥有C:\MyLog目录写的权限。3。同时,您还可以使用NetMornitor等网络软件,把浏览器端发送到服务器的HTTP包保存并进行分析。确定其中用来标示浏览器版本的HTTP_USER_AGENT(HTTP Header)的值。希望对您有所帮助。-微软全球技术中心  -zgh本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  3.   

    make sure you have an updated version of "browscap.ini" in C:\WINNT\system32\inetsrvdownload a copy from
    http://www.aspsimply.com/info/dlmeter.asp?cat=Info
      

  4.   

    to 微软专家 and saucer(思归):
       谢谢你们的回答.
    to 微软专家:
       我用以下方法:
    ...if(Request.ServerVariables["HTTP_USER_AGENT"].IndexOf("MSIE")>0)
    {
       string user_agent=Request.ServerVariables["HTTP_USER_AGENT"];
       int indexof_msie=Request.ServerVariables["HTTP_USER_AGENT"].IndexOf("MSIE");
       ieVersion=user_agent.Substring(indexof_msie+5,1);
       if(Int32.Parse(ieVersion)<6)
       {
         lblVersionErrMsg.Text="Please check your IE version,this website  can correctly work only in IE 6.0 or above version.";
         return;
       }
    ...确实可以正常工作,取得的版本也正确,但这里我还有两个问题:
    1.为什么Request.ServerVariables["HTTP_USER_AGENT"]可以取得正确的IE版本,而用Request.Browser.Version却得不到?
    2.Request.ServerVariables["HTTP_USER_AGENT"]中IE版本信息到底是客户端的,还是服务器端的?请指教,谢谢!
      

  5.   

    感谢您的回复。当用户(浏览器端)向Web服务器端发出请求的时候,发出的请求命令里面会包括一个“HTTP_USER_AGENT“ 字段(HTTP Header), 其中包括了浏览器的信息,比如说操作系统,浏览器名称,浏览器版本等。这是HTTP标准。您可以参阅RFC2616.Request.Browser.Version就是根据该HTTP Header得到浏览器端的信息的。如果您使用HTTP_USER_AGENT可以得到正确的信息,相信Request.Browser.Version也应该没有问题。建议您提供详细的代码,我们将尝试作进一步的分析。再次感谢您使用微软产品。本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  6.   

    1. Actually, I was wrongRequest.ServerVariables["HTTP_USER_AGENT"] is from the HTTP_USER_AGENT header sent back by the browser, while System.Web.HttpBrowserCapabilities class uses the information in C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.configsearch for "browserCaps" in machine.config, you might need updated browser capabilities information from http://www.cyscape.com/browsercaps2.客户端的
      

  7.   

    to 微软专家:
       感谢你的回答!
       我使用Request.Browser.Version的代码非常简单,就是在Page_Load()里面加入如下代码:HttpBrowserCapabilities bc = Request.Browser;
    string temp=bc.Version;
    Response.Write("Version = " + bc.Version + "<br>");
    Response.Write("Major Version = " + bc.MajorVersion + "<br>");页面上的输出为:
    Version = 0.0
    Majof Version = 0我的这个页面是整个项目的login页面,是不是因为项目的一些设置影响了结果?还是我的IE安装的问题?to saucer(思归):
    也非常感谢你的回答!
       C:\WINNT\Microsoft.NET\Framework\v1.0.3705\CONFIG\machine.config
    我察看了一下,好多啊!可不可以告诉我应该注意哪些键值?
      

  8.   

    search for "browserCaps", there is a section which looks like this: <!-- For updates to this browser data visit cyScape, Inc. at http://www.cyscape.com/browsercaps -->
            <browserCaps>
                <result type="System.Web.HttpBrowserCapabilities"/>
                <use var="HTTP_USER_AGENT"/>            browser=Unknown
                version=0.0
                majorversion=0
                minorversion=0
                frames=false
    .....
      

  9.   

    saucer(思归)讲得很对。问题可能是由于machine.config中的<browserCaps>导致的。在ASP.NET中,HttpBrowserCapabilities会根据<browserCaps>来解析HTTP_USER_AGENT。-微软全球技术中心  -zgh本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
    为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
      

  10.   

    to  saucer(思归) 和 zgh_ms([微软] 百变金刚) :
    非常感谢你们的回答,从中我也学到了很多东西。
    前两天由于机器重装,因此没能及时给你们回复,真是很对不起。
    我这里还有一个问题,在ASP.NET中,HttpBrowserCapabilities会根据<browserCaps>来解析HTTP_USER_AGENT,因此我的machine.config文件中的配置如果有问题就会导致我所说的问题发生,但是我想知道我用Request.ServerVariables["HTTP_USER_AGENT"]为什么可以了呢?他们实现的机制有什么区别吗?
    请指教,谢谢!
      

  11.   

    the information in Request.ServerVariables["HTTP_USER_AGENT"] is the raw header sent by the browser, and it looks like this:
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)as you can see, the information is very limited, ASP.NET then uses whatever between <browserCaps> to construct a System.Web.HttpBrowserCapabilities object, Request.Browser, and tell you more features about this browser (IE6 in this case)
      

  12.   

    再次真诚的感谢微软专家和saucer(思归)对我的帮助。:)五点钟结贴。