image

Acesse bootcamps ilimitados e +650 cursos pra sempre

60
%OFF

EA

Eduardo Andrade31/05/2022 13:51
Compartilhe

Projeto MVC .net 6.0 Área Program

  • #C#
  • #.NET

Na atualização do .net 5.0 para o 6.0 foi excluída a necessidade da área StartUP, segue como fica a área Program com os componentes Startup MVC

sing AutoCalc.Models;

using Microsoft.AspNetCore.Authentication.Cookies;

using Microsoft.EntityFrameworkCore;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllersWithViews();

// no lugar do startup utilizar o BUILDER.SERVICE

builder.Services.AddDbContext<ApplicationDbContext>(options =>

{

  options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection"));

});

// Método para guardar cookie.

builder.Services.Configure<CookiePolicyOptions>(options =>

{

  options.CheckConsentNeeded = ContextBoundObject => true;

  options.MinimumSameSitePolicy = SameSiteMode.None;

});

// Autenticação login e senha

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)

        .AddCookie(options =>

        {

          options.AccessDeniedPath = "/Usuarios/AcessDenied/";

          options.LoginPath = "/Usuarios/Login";

        });

builder.Services.AddControllersWithViews();

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.UseCookiePolicy();

// Login e Senha

app.UseAuthentication();

app.UseAuthorization();

app.MapControllerRoute(

  name: "default",

  pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();

Compartilhe
Comentários (0)