Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error route handler not rendering ui properly with asp.net core 3.x razor pages #182

Open
fingers10 opened this issue Mar 18, 2020 · 4 comments

Comments

@fingers10
Copy link

I came across this awesome nuget package to handle and log exceptions in asp.net core. I tried this in my razor pages application and things worked fine. However when I try to use error routes to see the errors, the page is not getting displayed properly.

My Error Page:

public class ErrorModel : PageModel
{
    public async Task OnGetAsync()
    {
        await ExceptionalMiddleware.HandleRequestAsync(HttpContext).ConfigureAwait(false);
    }
}

Here is the error route screen print:

enter image description here

Here is the console log:

enter image description here

Here is my ConfigureServices method:

services.AddExceptional(Configuration.GetSection("Exceptional"), options =>
{
    options.UseExceptionalPageOnThrow = Env.IsDevelopment();
});

Here is my Configure method:

app.UseExceptional();

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
    endpoints.MapRazorPages();
});

I even tried changing the middleware order by placing the app.UseExceptional() after app.UseStaticFiles(). But still it doesn't work. Please assist on why the assets are not getting loaded.

@NickCraver
Copy link
Owner

Hmmm, looks like a routing issue where the path is one off. Can please you show me the relative path of the page and the resources it's trying to load?

@fingers10
Copy link
Author

fingers10 commented Mar 19, 2020

Here you go,

It works if I use it in controllers as shown below:

public class ExceptionsController : Controller
{
    public async Task Index() 
    {
        await ExceptionalMiddleware.HandleRequestAsync(HttpContext).ConfigureAwait(false);
    } 
}

But not with razor pages as shown below:

public class ErrorModel : PageModel
{
    public async Task OnGetAsync()
    {
        await ExceptionalMiddleware.HandleRequestAsync(HttpContext).ConfigureAwait(false);
    }
}

Project Structure:
image

@agrath
Copy link

agrath commented Aug 17, 2020

I think I encountered a similar issue but I had the error page hosted in a controller.

Not sure if something similar is happening in razor pages routing.

In my case, I was using a routeprefix and route attribute like so:
image

CSS and sub-routes wouldn't work.
Found the fix for my particlular issue here: #154

image

Note: two changes, added ~ to bypass routeprefix (was testing this and it didn't work but decided to keep this)
The change that worked was adding {/{path?}/{subPath?}

@IronSean
Copy link

IronSean commented Dec 4, 2020

I also just ran into this, documenting the path definition requirements would help people get it running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants