Are configuration settings for identity correct ?

Ahmed Salah Abed Elaziz 390 Reputation points
2023-03-18T17:58:38.03+00:00

I work on .NET core 7 with blazor application web application .I need to check startup configuration for identioty is correct

or not so please tell me

are this configuration for identity login is correct and enough for setup identity or not please

I work on login with identity so i need to check configuration is correct or remaining some point need to add



namespace UC.AppRepository.UI
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

       
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddHttpClient();
            services.AddRazorPages();
            services.AddServerSideBlazor();
          
          
     

            services.AddHttpClient();

            services.AddAutoMapper(typeof(Startup));

            //Configration
            services.Configure<Schema>(Configuration.GetSection("Schema"));
            services.Configure<DBConnectionAppIds>(Configuration.GetSection("DBConnectionAppIds"));

          


            //DB Context 
            var connection = new DBCredentials().GetConnectionString(Configuration["DBConnectionAppIds:AppID"]);
            connection = connection + "TrustServerCertificate=True;";
            services.AddDbContext<AppsRepositoryDBContext>(options => options.UseSqlServer(connection));

            services.AddTransient(typeof(IRepository<>), typeof(BaseRepository<>));


            services.AddControllers();



            //Identity Authentication
            services.AddIdentity<IdentityUser, IdentityRole>(Option => Option.SignIn.RequireConfirmedAccount = false)
                  .AddDefaultUI()
                  .AddDefaultTokenProviders()
                  .AddEntityFrameworkStores<AppsRepositoryDBContext>();

          
        }

        // 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();
            }
            else
            {
                app.UseExceptionHandler("/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.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
}

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,137 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,375 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,243 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,199 questions
{count} vote

1 answer

Sort by: Most helpful
  1. JosePichardo22-9478 1 Reputation point
    2023-03-19T01:51:13.0366667+00:00

    namespace UC.AppRepository.UI

    {

    public class Startup
    
    {
    
        public Startup(IConfiguration configuration)
    
        {
    
            Configuration = configuration;
    
        }
    
        public IConfiguration Configuration { get; }
    
       
    
        public void ConfigureServices(IServiceCollection services)
    
        {
    
            services.AddHttpClient();
    
            services.AddRazorPages();
    
            services.AddServerSideBlazor();
    
          
    
          
    
     
    
            services.AddHttpClient();
    
            services.AddAutoMapper(typeof(Startup));
    
            //Configration
    
            services.Configure<Schema>(Configuration.GetSection("Schema"));
    
            services.Configure<DBConnectionAppIds>(Configuration.GetSection("DBConnectionAppIds"));
    
          
    
            //DB Context 
    
            var connection = new DBCredentials().GetConnectionString(Configuration["DBConnectionAppIds:AppID"]);
    
            connection = connection + "TrustServerCertificate=True;";
    
            services.AddDbContext<AppsRepositoryDBContext>(options => options.UseSqlServer(connection));
    
            services.AddTransient(typeof(IRepository<>), typeof(BaseRepository<>));
    
            services.AddControllers();
    
            //Identity Authentication
    
            services.AddIdentity<IdentityUser, IdentityRole>(Option => Option.SignIn.RequireConfirmedAccount = false)
    
                  .AddDefaultUI()
    
                  .AddDefaultTokenProviders()
    
                  .AddEntityFrameworkStores<AppsRepositoryDBContext>();
    
          
    
        }
    
        // 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();
    
            }
    
            else
    
            {
    
                app.UseExceptionHandler("/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.UseAuthorization();
    
            app.UseEndpoints(endpoints =>
    
            {
    
                endpoints.MapBlazorHub();
    
                endpoints.MapFallbackToPage("/_Host");
    
            });
    
            app.UseEndpoints(endpoints =>
    
            {
    
                endpoints.MapControllers();
    
            });
    
        }
    
    }
    

    }Browse

    0 comments No comments