Skip to main content

Posts

Showing posts from August 6, 2021

ASP.NET Core Session State Management

 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

ASP.NET Core Interview Questions : July 2022

1) What is appsettings.json? This .json file is holding the application configuration values for a.net core application, this is very similar to web.config or app.config in a legacy .net application  We can have multiple versions of the appsettings.json file Template: appsettings.[Environment].json Example:  * appsettings.DevEnv.json * appsettings.TestEnv.json * appsettings.Staging.json * appsettings.json  Little deeper: In order to load the configuration information into the application from the file we need the following class in the .net : JSON Configuration Provider Inherited from FileConfigurationProvider How to use: var _ConfigurationBuilder = new ConfigurationBuilder(Environment.ApplicationBasePath)               .AddJsonFile( "appsettings.Live.json" )                .AddEnvironmentVariables(); Configuration = _ConfigurationBuilder.Build();   2) What is the difference between ASP.NET CORE with .NET Framework and ASP.NET with .NET Core