How to create a mvc project in asp.net (Visual Studio)

Image
Hello Guys, We will learn how to create a  MVC Project in asp.net with MODEL, VIEW, CONTROLLER. As we know that Asp.net is give us a multiple options for programming language like C#, Java, Angular Js, React Js, Node Js and more integration inside our projects. So Today topic is how to create a MVC project in asp.net application. I am attaching snap of project step by step guys just follow and create your first application in mvc. Here I will teach you main error during adding project so guys please read it carefully and be a part of asp.net programming. Step One  just open visual studio and click on FILE choose NEW  and click on PROJECT Now Step Two After click project Just just insert your project name Like ( Online_Grocery ) for example name and click on OK wait for next window. After this step now this is the final options for your project you will choose which is the right option for you. Here is some option from asp.net application what is the base of your project s...

How to permanent login session in asp.net mvc

State management

State can be stored using several approaches. Each approach is described later in this topic.

STATE MANAGEMENT
Storage approachStorage mechanism
CookiesHTTP cookies. May include data stored using server-side app code.
Session stateHTTP cookies and server-side app code
TempDataHTTP cookies or session state
Query stringsHTTP query strings
Hidden fieldsHTTP form fields
HttpContext.ItemsServer-side app code
CacheServer-side app code

This code will help you for permanent login session

public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDistributedMemoryCache();

        services.AddSession(options =>
        {
            options.IdleTimeout = TimeSpan.FromSeconds(10);
            options.Cookie.HttpOnly = true;
            options.Cookie.IsEssential = true;
        });

        services.AddControllersWithViews();
        services.AddRazorPages();
    }

    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseSession();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapDefaultControllerRoute();
            endpoints.MapRazorPages();
        });
    }
}

Comments