Blazor app not using Exception Filter #18761
Labels
area-blazor
Includes: Blazor, Razor Components
✔️ Resolution: Answered
Resolved because the question asked by the original author has been answered.
question
Status: Resolved
I have a server-side Blazor application I'd like to use a custom Exception Filter for as per: https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-3.1#exception-filters.
Are these filters supported in a Blazor application?
Describe the bug
I'm trying to use the Microsoft.Identity.Web library and MSAL.NET to authenticate to the MSFT Graph. In this library there is a need to throw a
MsalUiRequiredException
and for a custom handler to deal with obtaining a new token. This issue is that I can't get my Blazor application, which right now is just the default template, to throw and catch the exception using the custom filter I created.Perhaps this is simply an issue with how the filter is being applied or maybe it's not supported yet, I don't know which one it is.
To Reproduce
Create a new Blazor server-side application and attempt to implement the same Exception Filter from the link above. I've tried to implement the filter in two different ways:
Startup.cs
by specifying theAuthorizeForScopesAttribute
as such:services.AddControllersWithViews(options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); options.Filters.Add(new AuthorizeForScopesAttribute(new[] {ScopeConstants.ScopeUserRead})); });
Set a breakpoint and throw a new exception. The breakpoint is never hit.
Further technical details
.NET Core SDK (reflecting any global.json):
Version: 3.1.101
Commit: b377529961
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.101\
Host (useful for support):
Version: 3.1.1
Commit: a1388f194c
.NET Core SDKs installed:
3.1.101 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
The text was updated successfully, but these errors were encountered: