Skip to content
Loading
  • Vishal  Patel
    0
    Please refer this URL: https://www.c-sharpcorner.com/UploadFile/dacca2/web-api-with-ajax-handle-session-in-web-api/
    0
  • Bhuban Magar
    0
    Hi,
    You can get and set session in .Net Core as,
    First add services.AddSession() and services.AddDistributedMemoryCache() inside ConfigureServices:
    public void ConfigureServices(IServiceCollection services)
    {
    services.AddMvc();
    ...
    services.AddDistributedMemoryCache();
    services.AddSession();
    } 
     
    In Controller,
     1. Set Session:
     
    [HttpPost]
    public IActionResult SetSession(user model)
    {
    HttpContext.Session.SetString("keyname", model.username);
    return Ok("session data set");
    }
     2. Get Session:
     
    [HttpGet]
    public IActionResult GetSession()
    {
    var sessionValue= HttpContext.Session.GetString("keyname");
    return Ok(sessionValue);
    }
    0
  • Sonu Gupta
    0
    Hi,
     
    Please go visit the below given url  - 
     
    https://stackoverflow.com/questions/57270555/how-to-set-session-use-by-asp-net-web-api-with-jquery-not-use-mvc
     
    https://www.c-sharpcorner.com/UploadFile/dacca2/web-api-with-ajax-handle-session-in-web-api/ 
    0
  • Bidyasagar Mishra
    0
    https://stackoverflow.com/questions/11478244/asp-net-web-api-session-or-something
    0