KEMBAR78
Constring Configure Sample | PDF
0% found this document useful (0 votes)
29 views1 page

Constring Configure Sample

This document outlines the setup of an ASP.NET Core web application using Entity Framework Core for database interactions. It configures services such as session management, HTTP context access, and database context with SQL Server. Additionally, it establishes middleware for error handling, HTTPS redirection, static file serving, routing, and authorization.

Uploaded by

24002071
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

Constring Configure Sample

This document outlines the setup of an ASP.NET Core web application using Entity Framework Core for database interactions. It configures services such as session management, HTTP context access, and database context with SQL Server. Additionally, it establishes middleware for error handling, HTTPS redirection, static file serving, routing, and authorization.

Uploaded by

24002071
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using Microsoft.

EntityFrameworkCore;
using socialNetworkClone.Models;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.


builder.Services.AddHttpContextAccessor();
builder.Services.AddControllersWithViews();
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});

builder.Services.AddDbContext<UserRoleDbContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("constring")));
var app = builder.Build();

// Configure the HTTP request pipeline.


if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for
production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

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

app.UseRouting();
app.UseSession();
app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

You might also like