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

Blazor app not using Exception Filter #18761

Closed
jasonshave opened this issue Feb 3, 2020 · 1 comment
Closed

Blazor app not using Exception Filter #18761

jasonshave opened this issue Feb 3, 2020 · 1 comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@jasonshave
Copy link

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:

  1. Applying the filter in Startup.cs by specifying the AuthorizeForScopesAttribute 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})); });

  1. Decorating the partial view class using the method described in the docs article.

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]

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Feb 3, 2020
@javiercn
Copy link
Member

javiercn commented Feb 4, 2020

@jasonshave thanks for contacting us.

Exception filters are not part of the Blazor programming model and are not supported. See this link for details on error handling in Blazor applications.

@javiercn javiercn added ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question labels Feb 4, 2020
@ghost ghost added the Status: Resolved label Feb 4, 2020
@javiercn javiercn closed this as completed Feb 4, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants