Click here to Skip to main content
15,887,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Como puedo asignar pagina de inicio en la clase de startup
Hola tengo este codigo en mi clase de Startup y quiero que cuando inicie mi proyecto me aparesca la vista del login ejmplo Identity/Account/Login
Hello, I have this code in my Startup class and I want the login view to appear when I start my project. Identity/Account/Login
C#
public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure<SmartSettings>(Configuration.GetSection(SmartSettings.SectionName));
            services.AddSingleton(s => s.GetRequiredService<IOptions<SmartSettings>>().Value);

            services.Configure<CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddIdentity<IdentityUser, IdentityRole>(options => options.SignIn.RequireConfirmedAccount = false)
                .AddRoleManager<RoleManager<IdentityRole>>()
                .AddEntityFrameworkStores<ApplicationDbContext>();

            services.AddTransient<IEmailSender, EmailSender>();

            services
                .AddControllersWithViews();

            services.AddRazorPages();

            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath = "/Identity/Account/Login";
                options.LogoutPath = "/Identity/Account/Logout";
                options.AccessDeniedPath = "/Identity/Account/AccessDenied";
            });

            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                options.IdleTimeout = TimeSpan.FromMinutes(1);//You can set Time   
            });
            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                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.UseAuthentication();
            app.UseAuthorization();
            app.UseSession();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    "default",
                    "{controller=Intel}/{action=MarketingDashboard}");
                endpoints.MapRazorPages();
            });
        }
    }
}


What I have tried:

Hola tengo este codigo en mi clase de Startup y quiero que cuando inicie mi proyecto me aparesca la vista del login ejmplo Identity/Account/Login
Quote:
Hello, I have this code in my Startup class and I want the login view to appear when I start my project, for example Identity / Account / Login
Posted
Updated 15-Jul-20 0:31am
v2
Comments
Patrice T 13-Jul-20 15:38pm    
English please.
Richard MacCutchan 13-Jul-20 16:10pm    
Please not this is (obviously) an English language site. If your English is not very good you can make use of Google translate.

1 solution

If you want to prevent anonymous users from viewing any of your pages, you need to ensure that all endpoints require authorization.

It's easy to set up a global authorization policy:
C#
app.UseEndpoints(endpoints =>
{
    endpoints.MapControllerRoute(
        "default",
        "{controller=Intel}/{action=MarketingDashboard}")
        .RequireAuthorization();
    
    endpoints.MapRazorPages().RequireAuthorization();
});
Setting global authorization policies using the DefaultPolicy and the FallbackPolicy in ASP.NET Core 3.x[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900