Gargml
Gargml

Reputation: 11

How do I determine if a HTTP request came from a browser or some agent

I would like to know what is the best practice for distinguishing between a request that was made from a browser, or some agent (Like postman for example, but also scripting tools). This is not for security measures, only different logic that should be applied, per the use case.

I am using the following approach:

HttpBrowserCapabilities browserCapabilities = context.Request.Browser;

if (browserCapabilities.Browser == "Unknown" && browserCapabilities.Id == "default") 

Which is working for me.

However, i wanted to hear your feedback on this method, and if you think that things can go wrong with this approach. I did not find any reference on Web to this approach, so i wonder what am i missing. Is it reliable or not ?

Please advise.

Upvotes: 1

Views: 1278

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 416131

The User Agent is the normal mechanism for this. Look at context.Request.Headers.UserAgent. And yes, some scripting tools will lie and pretend to be browsers. But if this really isn't about security, that's on them.

Upvotes: 2

Related Questions