views:

134

answers:

2

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 the clients browser in server side code.

Thanks.

+1  A: 

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.

BuildStarted
Morder, thank for your help.My requirement is for this to work on .net 1.1Some seem to say I should update the machine.config others the web.config.If I update the web.config the systems complains.If I update the machine.config the system still complains.All the information out there seem to be unclear.The machine.config already has entries for Firefox so why does the system say the first default option of 'unknown' :(
Hunt
Is App_Browsers just for .net 2 ?
Hunt
Ah. I'm sorry, I can't really answer that as I've *only* tested it on IIS7 with ASP.Net 3.5. The web.config method allows you to have it only available on one website vs. the entire machine. http://msdn.microsoft.com/en-us/library/sk9az15a.aspx this page seems to imply that it does work under the requirements and it appears that both web.config and machine.config work but it doesn't really say if there are any limitations as a result of 1.1...I'll keep looking around for you though
BuildStarted
http://msdn.microsoft.com/en-us/library/ms228122.aspx "Browser definition files were introduced the .NET Framework version 2.0. In earlier versions of the .NET Framework, the browserCaps element was used to define browser definitions in configuration files."
BuildStarted
Thanks I'm off to look at your links.
Hunt
http://msdn.microsoft.com/en-us/library/sk9az15a(VS.71).aspxsays below is valid for 1.1 and gives an example...<configuration> <browserCaps> <result type="System.Web.HttpBrowserCapabilities, System.Web"/>The line above creates an error...Parser Error Message: The 'type' attribute must be set to a valid Type name (format: <typename>,<assemblyname>)and list the errors...=== Pre-bind state information ===
Hunt
The rest of the error is...LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).LOG: Post-policy reference: System.WebLOG: Attempting download of new URL file:///c:/windows/microsoft.net/framework/v1.1.4322/Temporary ASP.NET Files/webapplication1/0ce05c64/4984f2c7/System.Web.DLL.I cannot understand why there would be problem with the system.web
Hunt
try this really quick: remove the `type` attribute from the `<result>` tag and see what happens - by default it's set to that type so removing it shouldn't cause any problems and might fix that error - else remove the `,System.Web` portion of the type attribute but off hand, without more research, I couldn't say what's wrong...
BuildStarted
<result type="System.Web.HttpBrowserCapabilities"/>gives... Type 'System.Web.HttpBrowserCapabilities' does not inherit from 'System.Web.Mobile.MobileCapabilities'.
Hunt
(remove the type) if you meant <result/>then that produces an error that indicates .net does not know what <browserCaps> is :(
Hunt
Just found this... Request.UserAgent it gives the correct response for IE,FireFox,Chrome,safari :)The only problem is parsing the string as can be seen -- User Agent :: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4 -- Chrome has Safari in the string as well :(
Hunt
Using just the Request.UserAgent .net 1.1 uses the Machine.config in the C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG.This can be proven by changing the <case match="^Mozilla/ sections browser=Netscape tag to ThisShouldHaveChanged
Hunt
Strange, I had that same "does not inherit" error recently but I don't think it was related to the web.config or machine.config. Here's my browser caps that I'm currently using - I can see it doesn't have the same `result type=''` that yours had: http://pastebin.com/QKGe1mdy Not sure if this is going to help but I'm presently out of ideas :)
BuildStarted
Your browser caps works without any changes (as is) in my web.config.I was not using -> System.Web.Mobile.MobileCapabilitiesWhat is the story behind using System.Web.Mobile.MobileCapabilities ?By the way Chrome is stated as Safari this is perhaps because the agent string is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4
Hunt
yeah, someone should update the xml element to support chrome/safari properly - or chrome should stop using "safari". The MobileCapabilities seems to be the one used for .net 1.x while it has been deprecated in later versions. Well I'm glad you got it working to a point. I hope it's what you want or at least works the way you want :)
BuildStarted
A: 

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.

Owen Brady