Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Chrome: how to find and display the browser information in Asp.Net Core 2 MVC.

23.04.2018 (πŸ‘10571)


 

I need the browser data of the client, so I can evaluate whether the browser is a mobile client for smartphones.

How can I determine the browser data is aspNetCore?

 

Solution:

The browser information can be read from the request header with the Key: User-Agent.

 

Code example in Core

String sHeader = Request.Headers["User-Agent"].FirstOrDefault();

ViewData["UserAgent"] = sHeader;

 

 

Display as test:

You can display the current browser information on the footer of a website as in this script

 

Asp.Net Core MVC C # code in the controller

 

Here, the header of the client browser is read and passed as ViewData to the view.

public   IActionResult Index()

{

    //-< goto View >--

    String sHeader = Request.Headers["User-Agent"].FirstOrDefault();

    ViewData["UserAgent"] = sHeader;

   

    return View("Index");

    //-</ goto View >--   

}

 

 

Razor code in the view

In the display view you can then simply display the ViewData value with Html.Raw (..)

<br />

<span style="display:block">

    @Html.Raw(ViewData["UserAgent"]);

 

</span>

 

 

 

In the Chrome browser:

In the Chrome browser you will find the current browser data under the. Network area

To do this, open the developer environment with Alt-Shift-I, go to Network and then refresh the website again.

Requerst View

GET /getuid?https%3A%2F%2Fads.avocet.io%2Fsync%3Finvsrc%3D5575b5a3d6e9d6ab4a43bc78%26ext_uid%3D%24UID HTTP/1.1

Host: secure.adnxs.com

Connection: keep-alive

User-Agent:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36

Accept: image/webp,image/apng,image/*,*/*;q=0.8

Referer: https://localhost:44390/

Accept-Encoding: gzip, deflate, br

Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

Cookie

: uuid2=520135025917438995; anj=dTM7k!M4/S@-f2S@yxQrbGDv'VkZ=P-RC!Fn]bTkls50%sn#/8*s5*v+oCc/VK^wS*hF9#X@.?^M)LV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ELde?d4.AI-3cymU>XwUaQJ*4BD^jQRmME.doJ0K#4%8yFPG=oV5G0s]W4*G/T0D'P$+7p@UfiYV$-vmJ#Q_Jm%[ww5>@]mcVXy%6Qq(!DC8_-mB39c9n%]e6BG*.(5TRpxWob.fT!5r.uOGp($?U.$H?24)'.H)B=svWxc<mhU5U>a=OZVr*Sj`:!F/KsZNk<b[rm+zyRb/h7ZK0r)sGmx`rCt'av(*C4$M4p[r!e02JGNsKZ+Bh!V`q5-xO`>az>s*V+/riD]D__2=S^<0'=UVc^91auBEoo%fRjF)^F#<xr88/`[45scm/VrMmH@?%!jyVWR(po'3ZC_^zJ^O1P'u$:5+M3FVR:)oK7UU'q.VRROVWF[alMF2paI%<DW0)?1$ziLj0kERT'+-$mZRp33DQfxW/A1B:LuHPX`nk?7imvkw)MOPHs$.N>s$jybYzc('jE$diO=UC=; sess=1; icu=ChwI_KBJEAoYGCCMASiMATCukPfWBTgSQIwBSIwBEK6Q99YFGIsB

config.js?nwid=1097         getuid?https%3A%2F%2Fads.avocet.io%2Fsync%3Finvsrc%3D5575b5a3d6e9d6ab4a43bc78%26ext_uid%3D%24UID     

 

Query in Asp.Net Core

Under Asp.Net Core you can read the header data with Headers ["User-Agent"].

It is best to use the Linq.FirstOrDefault () method to overload the values ​​onto a string.

 

The query of the HeaderUserAgent works like this: