locked
bootstrap reference from localfolder is not working RRS feed

  • Question

  • User-258593967 posted

    Hello,

    i installed vs 2017 and .net core 2.2. I added bootstrap to my application through 'add clientside library' to my wwwroot folder. I'm working with mvc right now, Anything i referred from wwwroot like css is not getting applied. i dont what to do. If i check on a html page, the bootstrap is getting applied, but not on view file. if i refer url from cdn it works, but not to able get applied from local folder wwwroot?

    Thursday, October 29, 2020 8:55 PM

Answers

  • User-826336654 posted

    Hi,

    In Startup.cs file inside Configure Method, Add the following code

    app.UseStaticFiles(); 

    The complete code is below. Add the yellow highlight code in your startup.cs file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.HttpsPolicy;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    
    namespace WebApplication47
    {
        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.AddControllersWithViews();
            }
    
            // 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("/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.UseAuthorization();
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Site}/{action=Index}/{id?}");
                });
            }
        }
    }
    

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 29, 2020 10:33 PM

All replies

  • User-474980206 posted

    the bootstrap file should be in "wwwroot/lib/bootstrap/dist" and the css link look like:

      <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />

    also as core 2.2 is no longer supported (ended 12/23/2019), you should upgrade to 3.1 or drop back to 2.1

    Thursday, October 29, 2020 10:01 PM
  • User-826336654 posted

    Hi,

    In Startup.cs file inside Configure Method, Add the following code

    app.UseStaticFiles(); 

    The complete code is below. Add the yellow highlight code in your startup.cs file

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.HttpsPolicy;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using Microsoft.Extensions.Hosting;
    
    namespace WebApplication47
    {
        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.AddControllersWithViews();
            }
    
            // 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("/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.UseAuthorization();
    
                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllerRoute(
                        name: "default",
                        pattern: "{controller=Site}/{action=Index}/{id?}");
                });
            }
        }
    }
    

    Thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 29, 2020 10:33 PM
  • User-258593967 posted

    Hi eaak,

    This works. Thank you so much.

    Friday, October 30, 2020 5:03 PM
  • User-258593967 posted

    Bruce, yes I have this. Thank you

    Friday, October 30, 2020 5:08 PM