HttpRequest.ServerVariables vs HttpRequest.UserAge

2019-05-07 13:45发布

问题:

What would be the difference (if any) and advantages/disadvantages between these two properties used to determine the user agent?

Dim strUserAgt as String
userAgent = Request.userAgent

vs.

Dim strUserAgt as String = Request.ServerVariables("HTTP_USER_AGENT")

回答1:

Source: How to determine browser type in server-side code without the BrowserType object in ASP.NET

In ASP.NET, you can access the Request.ServerVariables collection or use the new Request.UserAgent property to retrieve the HTTP_USER_AGENT header value.

There are no difference, both will retrieve same thing HTTP_USER_AGENT header value.

Check Request.ServerVariables Collection and IIS Server Variables if you want to dig it in deep. These server variables collection values somewhat depend ond the IIS version also.