This site uses cookies to deliver our services. By using this site, you acknowledge that you have read and understand our Cookie and Privacy policy. Your use of Kontext website is subject to this policy. Allow Cookies and Dismiss

Retrieve Http client request metadata like IP address and languages in asp.net core

1367 views 0 comments last modified about 12 months ago Raymond

dotnet core asp.net core

IP Address

In ASP.NET Core, Request.UserHostAddress has been removed though that attribute exists in the traditional ASP.NET applications.

We can use HttpContext.Connection to retrieve the remove client IP address:

var ipAddress = HttpContext.Connection.RemoteIpAddress?.ToString();

Note

This IP address may not be the direct IP address of the user.  For example, user may use VPN, proxy and etc.

User Agent

Through user agent, we can get users’ browser information.

var userAgent = Request.Headers["User-Agent"];

User Languages

To support localization and globalization, user language is also important. Accept-Language request header can be used for this purpose. However, this attribute is an array and even the element can include multiple languages separated by semi comma. For example, “en-US, en, *”.

var languages = Request.Headers["Accept-Language"];

Related pages

Set AttachDbFilename as Relative Path in .NET Core

145 views   0 comments last modified about 3 months ago

.NET Framework, you can use |DataDirectory| to configure connection string when connecting to SQL Server database file via attach mode: AttachDbFilename=|DataDirectory|\dbname.mdf In .NET Core, you cannot directly set SQL Server Express connec...

View detail

Instantiate a Service in ConfigureServices Method in .NET Core

31 views   0 comments last modified about 3 months ago

.NET Core is built in with dependency injection. Usually method ConfigureServices in Startup class is used to register services in the container. The signature of the method looks like the following: public void ConfigureServices(IServiceC...

View detail

ASP.NET Core 2.1 Error - 'Cyrillic' is not a supported encoding name

142 views   0 comments last modified about 3 months ago

After upgrading to ASP.NET Core 2.1 (.NET Core SDK 2.1.301), you may encounter the following error about encoding: System.ArgumentException    HResult=0x80070057    Message='Cyrillic' is not a supported encoding name. For information on defining a custo...

View detail

SQLite in .NET Core with Entity Framework Core

84 views   0 comments last modified about 3 months ago

SQLite is a self-contained and embedded SQL database engine. In .NET Core, Entity Framework Core provides APIs to work with SQLite. This page provides sample code to create a SQLite database using package Microsoft.EntityFrameworkCore.Sqlite . Create sample project ...

View detail

Graphics Programming and Image Processing in .NET Core 2.x

48 views   0 comments last modified about 3 months ago

In .NET Core 2.x, Windows Forms or WPF are not implemented since they are based on GDI+ and DirectX respectively in Windows. In .NET Core 3.0, there is plan to add Desktop Packs which includes UWP. WPF and Windows Forms. However, they will still be Windows-only. In .NET Core applications, you may...

View detail

Graphics Programming and Image Processing in .NET Core 2.x

48 views   0 comments last modified about 3 months ago

In .NET Core 2.x, Windows Forms or WPF are not implemented since they are based on GDI+ and DirectX respectively in Windows. In .NET Core 3.0, there is plan to add Desktop Packs which includes UWP. WPF and Windows Forms. However, they will still be Windows-only. In .NET Core applications, you may...

View detail

Add comment

Please login first to add comments.  Log in New user?  Register

Comments (0)

No comments yet.