In ASP.NET Core the state is maintained in following ways
Traditional ASP.NET Sessions
This can be accessed throughout the application using the
1) HttpContext.Items
Example:
var username = _httpContextAccessor.HttpContext.User.Identity.Name;
2) Session Items, this is based on IServiceCollectionm
This can be accessed via
IServiceCollection services;
services.AddSession(options =>
{
options.Cookie.HttpOnly = true;
});
3) Cookies: A local browser storage which is widely used in at most all the web based applications
4) Query Strings : URL Based state management
5) HiddenFields : Stored locally in the browser, unlike Cookies this is Persistent until the page lives, if the user traverses to another page this value will be disappeared
6) TempData : Across actions or views but only to the same controller, if it is used then the data will be last until the last usage
Comments