-1

Upgrading .net 4.8 mvc app to .net 6. I am keeping the static content in the same folders as in the previous web app project and using the web optimizer to minify and bundle.

I am seeing lot of console errors and the UI is not loading for the app

enter image description here

Layout cshtml enter image description here

Script and Content folder

enter image description here

enter image description here

Lucky
  • 81
  • 6
  • Welcome to Stack Overflow. Please provide a [mcve]. – Twisty Jan 30 '23 at 06:25
  • It is a part of big app so I am unable to make that happen quickly. I am trying to work on the same it might take some time as I am new, but if anyone has any suggestions please do let me know – Lucky Jan 30 '23 at 09:18

1 Answers1

0

It may help if you could show how you configured in program.cs

I tried as the document :

In program.cs:

builder.Services.AddWebOptimizer(x =>x.AddJavaScriptBundle("/js/bundle.js", "js/chat/*.js"));

call

app.UseWebOptimizer();

before:

app.UseStaticFiles();

in chat.js:

console.log("chat");

in hellow.js:

console.log("hellow");

And my project:

enter image description here

in my View,I called:

<script src="/js/bundle.js"></script>

The result:

enter image description here

other document may help:

Update:

I tried to add two floders under the directory of the project as your comment and tried as below to fix the 404 error:

var provider1 = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Script1"));
    var provider2 = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(builder.Environment.ContentRootPath, "Script2"));
builder.Services.AddWebOptimizer
(x =>
 {    
x.AddJavaScriptBundle("/bundle1.js","/chat/*.js").UseFileProvider(provider1); 
   x.AddJavaScriptBundle("/bundle2.js","/comment/*.js").UseFileProvider(provider2);
});

My project:

enter image description here

Ruikai Feng
  • 6,823
  • 1
  • 2
  • 11
  • Hi Ruikai Feng, Thank you so much for your response. I did create a small app when trying weboptimizer myself and did refer the js and css as shown in my snapshot For e.g. and – Lucky Jan 30 '23 at 09:53
  • In program cs I do have builder.Services.AddWebOptimizer(pipeline => { pipeline.AddCssBundle("/css/css", "Content/file1.css","Content/Level/file2.css").UseContentRoot(); var provider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),"Scripts")); pipeline.AddJavaScriptBundle("/js/Scripts","Lvlchk/*.js").UseFileProvider(provider); }); and UseWebOptimizer(); before UseStaticFiles call – Lucky Jan 30 '23 at 09:53
  • I have Content folder under which I have file 1 css and Level folder which has file2 css and have a Scripts folder that has one site.js under a folder Lvlchk. Since all this worked in my sample app this is why I implemented similarly in the original app which is giving me those issues shown in the main question snap – Lucky Jan 30 '23 at 09:54
  • I tried to move the js files into two different floders under the directory of the project (not wwwroot)and reproduced the 404 error you've got, I defined two providers instead of one with .UseContentRoot() and one with .UseFileProvider(provider) and solved the 404 error – Ruikai Feng Jan 31 '23 at 06:59
  • The 403 error seems have no relationship with WebOptimizer – Ruikai Feng Jan 31 '23 at 07:08
  • In my sample app it does resolve but I do not think it will work for me to create multiple provider path every time and folders. I am switching to bundleconfig (Bundling and Minification extension in VS) – Lucky Jan 31 '23 at 12:46
  • it may help if you could upload the minimal codes that could reproduce the error to github – Ruikai Feng Feb 01 '23 at 05:38