Skip to content
Loading
  • +2

    @ Sachin

    I am using .net core 

    string strHostName = HttpContext.Connection.RemoteIpAddress;

    getting and error "object doesnot contain and definition for connection no accessible method for connection."

    What connection are using here? 

    +2
  • Sachin Singh
    +2

    @Saumya

    HttpContext.Connection is a property that helps to Get information about the underlying connection for the current request.

    applicable to  .net core 2.1, 1.0, 1.1, 2.0, 2.2, 3.0, 3.1, 5.0 

    Namespace: Microsoft.AspNetCore.Http

    Assembly: Microsoft.AspNetCore.Http.Abstractions.dll

    Package: Microsoft.AspNetCore.App.Ref v5.0.0

    +2
  • Arnab Mukherjee
    +2
    Hi Sowmya, Please check the link given below.
     
    https://stackoverflow.com/questions/28664686/how-do-i-get-client-ip-address-in-asp-net-core 
    +2
  • Aman Gupta
    +1

    Hi, use it like this,

    HttpContext.Session.SetString("session name","session string"); 
    var priceDetails = HttpContext.Session.GetString("session name");

    Don't forget to add

    services.AddSession();

    in ConfigureServices and add

    app.UseSession();

    in Configure first. 

    More details, you can check the official link:

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/app-state?view=aspnetcore-5.0

    +1