1
votes

I'm in C# land today. I'm trying to write a function which accepts a user agent string and returns an object that gives me at least the browser name and version. So I tried this answer, but apparently I don't have access to HttpBrowserCapabilities. It tells me the type or namespace name could not be found (yes, even if I add using System.Web, it still doesn't show up, or when I type using System.Web. it doesn't pop up, so it's obviously not there).

I'm using .net 3.5, but the documentation for that class shows it existed even in 3.5, so I'm not sure what's going on. I have access to the browscap files - ini or xml. Am I going to have to write this from scratch?

Edit: I've fixed the reference problem. But Chrome is being reported as AppleMAC-Safari 5.0. I'm wondering if I'm going to need a completely different approach. PHP figures it out with the same ini file fine.

3
Did you add a reference to System.Web? If the assembly isn't referenced, then the using is useless. - BradleyDotNET
You might be interested in having a look at this post.. stackoverflow.com/questions/2221722/browser-detection?rq=1 - Aman Thakur
Thank you @BradleyDotNET that did fix my error. - Andrew
@AmanThakur I did notice the problem they mention in that question, too, regarding Chrome being reported as AppleMAC-Safari. I guess this approach won't work at all. - Andrew
@Andrew If someone provides an answer that solves your problem, you should click the green checkmark next to it to accept their answer. That shows other people it solved your problem. - mason

3 Answers

2
votes

Adding a using block does not automatically import the DLL. All a using does is allow you to not write:

System.Web.HttpClient //Or whatever

All over the place, and use HttpClient instead.

You need to add a reference to System.Web to the project before any of its classes will be available to you.

1
votes

Did you have a using System.Web; statement in your source file?

Here's a tip: if you're using Visual Studio, and you have a reference to the System.Web.dll in your project, if you type the name of a type and press Ctrl-. it will give you a popup menu to add the namespace reference to your source file.

0
votes

Do you see it in the ObjectBrowser (assuming you are using Visual Studio)? I found the namespace this morning (granted I'm on 4.5 - but documentation shows it has been around since 3.5 and earlier)

Object Browser for System.Web