1

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.

Community
  • 1
  • 1
Andrew
  • 1,571
  • 17
  • 31
  • Did you add a *reference* to `System.Web`? If the assembly isn't referenced, then the `using` is useless. – BradleyDotNET Feb 03 '15 at 18:01
  • You might be interested in having a look at this post.. http://stackoverflow.com/questions/2221722/browser-detection?rq=1 – Aman Thakur Feb 03 '15 at 18:07
  • @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 Feb 03 '15 at 18:33
  • @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 Feb 03 '15 at 19:22
  • @mason I'll be sure to do that once the problem is solved. – Andrew Feb 03 '15 at 19:59
  • Whatever I'll open a new question even though it's the same question. – Andrew Feb 03 '15 at 20:19

3 Answers3

2

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.

BradleyDotNET
  • 60,462
  • 10
  • 96
  • 117
1

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.

Erik
  • 5,355
  • 25
  • 39
0

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

TrampSansTom
  • 188
  • 3
  • 9