skip to Main Content

I am working on a project in Angular and ASP.NET Core hosted on Plesk. The project is working fine except the page refresh yields the 404 page not found error. Whenever I hit refresh from the browser or reload the page, it gives the 404 error.

The structure of the files it’s in the picture below.

The content in web.config is:

In the "wwwroot" folder I have the build from Angular, where I created a "web.config" file with the following content:

Also in the "wwwroot" folder, I have the "index.html" file with the following content:

Please guide me to solve this issue.

Thanks!

3

Answers


  1. Did you try adding

     <action type="Rewrite" url="./index.html" />
    

    instead of

     <action type="Rewrite" url="/" />
    
    Login or Signup to reply.
  2. I ran in the same problem last night, but with a Vue application that uses ASP .net 6.0 in the backend.
    The reason of the error is well explained here, but I used a different solution to solve this problem.

    My solution was adding a MapFallbackTocontroller controller in program.cs:

    app.MapControllers();
    app.MapFallbackToController("Index", "Fallback");
    
    await app.RunAsync();
    

    and then creating said FallbackController.cs:

    [AllowAnonymous]
    public class FallbackController : Controller
    {
       public IActionResult Index()
       {
          return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html"), "text/html");
       }
    }
    
    Login or Signup to reply.
  3. Net 6 and angular spa application refresh 404 issue appears.Along with index html changes add below lines in program/startup.cs refreshing issue fixed .
    snippet mentioned here

    app.Use(async (context, next) =>{
                await next();
                if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
                {
                    context.Request.Path = "/index.html";
                    await next();
                }
            }); 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search