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.

6
  • Did you add a reference to System.Web? If the assembly isn't referenced, then the using is useless. Commented Feb 3, 2015 at 18:01
  • You might be interested in having a look at this post.. stackoverflow.com/questions/2221722/browser-detection?rq=1 Commented Feb 3, 2015 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. Commented Feb 3, 2015 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. Commented Feb 3, 2015 at 19:22
  • @mason I'll be sure to do that once the problem is solved. Commented Feb 3, 2015 at 19:59

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

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

1 Comment

Negative. I've added the reference and there's no longer an error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.