Search code examples
c#.net-corerazorhttp-status-code-404iis-10

Razor Pages (dotnet core) - 404


We have an app built on dotnet core (currently 5, will be upgrading to 6 soon) that has a very strange issue. 95% of the web app runs perfectly, but there is a single razor page that generates a 404 - but only when deployed to the production server. Within Visual Studio it all works as expected, but even using dotnet MySite.dll (the .exe version of that command didn't work - it said a duplicate reference existed in the deps.json file with a different extension, but targeting the .dll version did what I expected) which spins up a "development" web server on ports 5000/5001, but even that gets the 404 on this one single page. All other pages work (including partial views) as expected.

The code on the page is about as basic as it comes, because it's a partial view setup like this:

@page "/providers/information"
@model ProviderInformationChangeRequestModel
@{
    Layout = null;
}

The rest of the content on the page is just HTML - it's got a form, textbox and button on it, so nothing fancy there. Behind the razor page it's also quite basic:

public async Task<IActionResult> OnGet()
        {
            //EntityModel is a public property exposed on our base `PageModel` class (ours extends the Microsoft one)
            this.EntityModel = new ProviderChangeModel();

            //this is an API call - we use this exact call all over the site, so presumably it isn't failing, since it works everywhere else
            var entity = await this.GetFromJsonAsync<ProviderUserModel>("/user/me");

            this.EntityModel.ProviderUserId = entity.Id;
            this.EntityModel.ProviderId = entity.ProviderId.Value;

            return Page();
        }

Every other partial view we have using this type of structure works - both deployed and through VS - and it's just this one page that won't work. I've read that this can sometimes happen when a Razor page makes backend API calls if one of those kicks back a 404, but the only call it makes is one we use throughout the site so it can't be that.

Does anyone have any ideas that can point us in the right direction? If it was failing in VS it'd be easy to track down, but since it's only the deployed version (which I've redeployed multiple times, restarted corresponding app pools and so on), I'm at a loss.


Solution

  • Well that was quick. A friend looked at it and realized the Build Type on the cshtml page was set to None instead of Content - how it worked in VS I'm not sure I understand, but at least it's solved now.