简体   繁体   中英

Core 2 MVC Can't access wwwroot lib

I am making the switch over to Core 2 from .Net and rather than using templates provided by VS2017 I wanted to create an app from scratch to see the workings. I am however using a template project to check against for when I get stuck but I can't see what is causing the access issue.

The issue I'm getting is when I run the web application, none of the content from wwwroot/lib is being accessed. The environment is development, and the links are specified as such within the layout:

<environment include="Development"> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" /> <link rel="stylesheet" href="~/css/site.css" /> </environment>

If I take the links out of the environment element, they still can't be accessed, using fiddler I can see a 404 error but the files are there.

These files are present in the project, installed through bower and the files are referenced in the bower.json file. The .bowerrc file specifies the wwwroot/lib as where to store the content.

My Configure method in the StartUp is as below:

    `public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseBrowserLink();
        }
        else
        {
            app.UseExceptionHandler("/Home/Error");
        }

        app.UseStaticFiles();
        // to get cookie authentication to work
        app.UseAuthentication();

        app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });
    }`

What could be causing this restricted access to the wwwroot/lib ?

Edit 1:

Initially @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers wasn't working from _ViewImports but I couldn't see why, bootstrap was working at this point. The only change I made was to add @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers at the top of the layout file, which made all of the asp- elements work. However nothing was being access in the wwwroot/lib .

No big deal, removed the @addTag from the layout, and wwwroot still couldn't be accessed. I've since restarted visual studio, multiple rebuilds and cleans but nothing has worked. Weirdly, since removing @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers from layout, ViewImports is working I think as the asp- helpers still function.

Edit 2:

I have published to a remote IIS server and it is running with the correct content no problem. With this in mind I have installed IIS on my local machine, instead of IIS Express. When I run this in debug it still isn't picking up the correct content.

Edit 3:

Not sure why or how but _ViewImports.cshtml appears to be the issue. If I remove it, the application picks up the styling, however I still cannot access the .css. or .js files through the browser. The browser console also reports errors that the content cannot be accessed, so how it's picking up the styling is a bit confusing!

Not a solution as such, I had to start a new project and copied the contents of the files across and it worked. The only difference to the project set up was files like _ViewImports.cshtml I added using the specific file, not renaming a view. It looks identical so I don't know if there are behind the scenes reasons for this.

I had the same issue. In my case it was related to permissions under wwwroot folder. What worked for me was: Right Click on wwwroot folder in Windows Explorer => Properties => Uncheck Read Only

I know this thread is a bit old, but encountered the same problem. It could be related to this.

https://github.com/aspnet/LibraryManager/issues/373

My issues was that the files were ignored via Source Control as I added them via Visual Studio 'Client Side Library' helper. Visual Studio showed a little red icon on the file in the solution explorer as opposed to blue padlock (I just happened to miss this).

I right clicked on the lib folder and 'Add Ignored File(s) to Source Control'.

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