开发者

Has anyone got HttpBrowserCapabilities working in asp.net

开发者 https://www.devze.com 2023-01-04 11:27 出处:网络
HttpBrowserCapabilities browse = Request.Browser; just seems to bring back IE or Netscape for all other browsers.

HttpBrowserCapabilities browse = Request.Browser; just seems to bring back IE or Netscape for all other browsers.

I have updated the C:\WINDOWS\system32\inetsrv browscap.ini file on the developer pc that has asp.net c#.

My requirement is to trap 开发者_JAVA技巧the clients browser in server side code.

Thanks.


This is the version for 1.1 for Dot.net

http://owenbrady.net/browsercaps/CodeProject.xml

You have to copy it into the proper area in your web.config though.


http://owenbrady.net/browsercaps/ This is an xml file that you add to your web.config that gives detailed information back to the browsercapabilities structure. This should do what you're looking for.

Edit: I've only tested this on IIS7 and Asp.Net 3.5.


Have a look at the App_Browsers folder, you can add a .browser file to expand the detection of the Request.Browser object in ASP.net.

For example: to detect a BlackBerry you need the following rule e.g. blackberry.browser added to the App_Browsers folder:

<browsers>    
  <browser id="BlackBerry" parentID="Default">
    <identification>
      <userAgent match="BlackBerry(?'model'\d+)/(?'version'((?'major'\d+).(?'minor'\d+).(?'other'\d+)))" />
    </identification>
    <capabilities>
      <capability name="browser"     value="BlackBerry" />
      <capability name="isMobileDevice"     value="true" />
      <capability name="javascript"     value="true" />
      <capability name="ecmascriptversion"     value="1.3" />
      <capability name="version"     value="${version}" />
      <capability name="majorVersion"     value="${major}" />
      <capability name="minorVersion"     value="${minor}" />
      <capability name="supportsCss"     value="true" />
      <capability name="css1"                            value="true" />
      <capability name="css2"                                    value="true" />
      <capability name="frames"     value="false" />
      <capability name="cookies"     value="true" />
      <capability name="mobileDeviceManufacturer"   value="RIM" />
      <capability name="isColor"                         value="true" />
      <capability name="supportsBold"                    value="true" />
      <capability name="supportsFontName"                value="true" />
      <capability name="supportsImageSubmit"             value="true" />
      <capability name="supportsItalic"                  value="true" />
      <capability name="preferredImageMime"              value="image/jpeg" />
    </capabilities>
  </browser>
</browsers>

Now you can keep adding your own forever, but there was a project from Microsoft that has thousands of devices in their file: MDBF, but they shut this project down recently (but the last version is still accessible). So the alternative is to include 51degrees.codeplex.com It's not as easy as MDBF was, but should get the job done.


Using .Net 3.5, I've got HttpBrowserCapabilities working with the browsercaps section of the web.config commented out. Here's what I have, validated in IE 8, Firefox, Chrome, and Safari on the same machine.

        System.Web.HttpBrowserCapabilities browser = Request.Browser;

        BrowserNm.Text = browser.Browser;
        BrowserVer.Text = browser.Version;
        Platform.Text = browser.Platform;

My requirements for browser detection are similar, but we don't want to use browsercaps at all. If you are intent on using browsercaps, you might as well write regular expressions to identify browsers, which was our first option, which I hated.

Three properties I'm still investigating are IsMobileDevice, MobileDeviceManufacturer, and MobileDeviceModel. If i know those work, I'm golden.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号