简体   繁体   中英

Loading Static Files from Controller ASP Net Core MVC

I have a puzzling problem, my application loads static files from controller folder, but in default route it loads normally

Example:

https://localhost:44369/plugins/bootstrap/js/bootstrap.bundle.min.js (in normal situation) (needs to be work)

In my situation

https://localhost:44369/Order/plugins/bootstrap/js/bootstrap.bundle.min.js

It wants to load from static files from controller folder which does not exist.

I use Admin LTE 3 Template (maybe the template has some issues?)

Thank you :)

Startup.cs

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.AddHttpClient();
        services.AddAutoMapper(typeof(Startup));
        services.AddControllersWithViews().AddRazorRuntimeCompilation();
        services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
        services.AddSingleton<ICustomerService, CustomerManager>();
        services.AddSingleton<ICustomerDal, CustomerDal>();
        services.AddSingleton<IInformationResourcesService, InformationResourcesManager>();
        services.AddSingleton<IInformationResources, EFInformationResourcesDAL>();
        services.AddSingleton<INewOrderService, NewOrderManager>();
        services.AddSingleton<INewOrderService, NewOrderManager>();
        services.AddSingleton<INewOrderDal, EfNewOrderDalL>();
        services.AddSingleton<ICityDal, EFCityDal>();
        services.AddSingleton<ICityService, CityManager>();
        services.AddSingleton<IDisctrictDal, EFDistrictDal>();
        services.AddSingleton<IDistrictService, DistrictManager>();
        services.AddSingleton<IVillageDal, EFVillageDal>();
        services.AddSingleton<IVillageService, VillageManager>();
        services.AddSingleton<IStreetDal, EFStreetDal>();
        services.AddSingleton<IStreetService, StreetManager>();
        services.AddSingleton<ICustomerAdressService, CustomerAdressManager>();
        services.AddSingleton<ICustomerAdressDal, EFCustomerAdressDal>();

        //services.AddCors(options =>
        //{
        //    options.AddPolicy("CorsPolicy",
        //        builder => builder
        //            .AllowAnyMethod()
        //            .AllowCredentials()
        //            .SetIsOriginAllowed((host) => true)
        //            .AllowAnyHeader());
        //});
        //services.AddDependencyResolvers(new ICoreModule[] {
        //    new CoreModule()
        //});
    }

    // 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.UseStaticFiles();
        app.UseHttpsRedirection();
        app.UseRouting();

        app.UseAuthorization();
        //app.UseCors("CorsPolicy");

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Customer}/{action=Index}/{id?}");
        });
    }
}

Can you specify how you are adding the script to your page. I am using a template as well and my scripts are located in wwwroot/vendors folder this is my script tag.

<script src="~/vendors/jquery/dist/jquery.min.js" type="text/javascript"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM