Trying to get the user-agent from request in asp.net web api self host

后端 未结 5 1864
轻奢々
轻奢々 2021-02-05 00:21

I\'m trying to get the user-agent in a web api self host and I\'m either doing it wrong, or the web api itself is altering the user agent string.

I\'ve tried using sever

5条回答
  •  你的背包
    2021-02-05 00:44

    The answer is simple try the following. It's shorter and less likely to break.

    String userAgent;
    userAgent = Request.UserAgent;
    

    It will give you a string similar to this one.

    Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)
    

    Documentation: http://msdn.microsoft.com/en-us/library/system.web.httprequest.useragent.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

提交回复
热议问题