alirizaadiyahsi / Nucleus

Vue startup application template that uses ASP.NET Core API layered architecture at the back-end and JWT based authentication
MIT License
355 stars 86 forks source link

Hosting IIS Server? #196

Open rafiqcse opened 2 years ago

rafiqcse commented 2 years ago

Can you help me, how to deploy and hosting to IIS server this project? Please share detail steps for hosting so that we can login to main page. This project is working perfectly in development mode, I can debug everything, and also I can host client part. But when login to access main page menu then server side through the following error. Failed to load resource: net::ERR_CONNECTION_REFUSED Please help me.

rafiqcse commented 2 years ago

At last I succeed to deploy the project to IIS following below instruction

  1. Install .net hosting bundle, urlrewrite2, httpPlatformHandler_amd64.msi, WebPlatformInstaller_x64_en-US.msi

  2. hosts file location C:\Windows\System32\drivers\etc -127.0.0.1 nucleus.com

  3. Adding a website for Vuejs client project to iis –In this case hosts file name nucleus.com should same host name in iis.

  4. Adding a web application under client to iis as named api

  5. Please go to binding section after selecting client website in iis -Adding another binding whose type https and port 44323 (port may change)

  6. Please select api in IIS and double click to SSLSettings -Select Require SSL and Accept then apply changes.

  7. Please add named “api” as per server name in IIS to the url in appsettings.Production.json, launchSettings.json, .env.Production, appSettings.json

  8. Please change startup class in server project as follows

    private readonly IConfiguration _configuration;
    public Startup(IConfiguration configuration)
    {
        _configuration = configuration;
    }
    public void ConfigureServices(IServiceCollection services)
    {
        services.ConfigureDbContext(_configuration);
        services.ConfigureAuthentication();
        services.ConfigureJwtTokenAuth(_configuration);
        services.ConfigureCors(_configuration);
        services.ConfigureDependencyInjection();
        services.ConfigureNucleusApplication();
        services.ConfigureSmtp(_configuration);
    
        services.AddControllers(setup =>
        {
            setup.Filters.AddService<UnitOfWorkActionFilter>();
        }).AddNewtonsoftJson();
    
        services.AddSwaggerGen(options =>
        {
            options.SwaggerDoc("v1", new OpenApiInfo { Title = "Nucleus API", Version = "v1" });
            options.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
            {
                Description = "Standard Authorization header using the Bearer scheme. Example: \"bearer {token}\"",
                In = ParameterLocation.Header,
                Name = "Authorization",
                Type = SecuritySchemeType.ApiKey
            });
    
            options.OperationFilter<SecurityRequirementsOperationFilter>();
        });
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment() || env.IsProduction())
        {
            app.UseDeveloperExceptionPage();
        }
        else
        {
            app.UseHsts();
        }
        app.UseSwagger();
        app.UseSwaggerUI(c =>
        {
            c.SwaggerEndpoint("/swagger/v1/swagger.json", "Nucleus API V1");
        });
    
        app.UseCors(_configuration["App:CorsOriginPolicyName"]);
        app.UseHttpsRedirection();
        app.UseRouting();
        app.UseAuthentication();
        app.UseAuthorization();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
        });
    }