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

Accessing HttpContext.Items fails on WebKit browsers #17585

Closed
sven5 opened this issue Dec 4, 2019 · 2 comments
Closed

Accessing HttpContext.Items fails on WebKit browsers #17585

sven5 opened this issue Dec 4, 2019 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question

Comments

@sven5
Copy link

sven5 commented Dec 4, 2019

We're developing a .NET Core 3.1 Blazor application.
In short, we use custom middleware to authenticate the User and store the IdentityUser object in the HttpContext.Items collection to retrieve it later in a scoped service. This works fine for most scenarios. However, there seems to be a problem when using a WebKit device (Apple iPad). The HttpContext.Items is always null. It seems that the behavior is different than with other browsers.

The following code is throwing:
public IntranetUser User => _httpContextAccessor.HttpContext?.Items["IntranetUser"] as IntranetUser;

StackTrace:

System.ObjectDisposedException: IFeatureCollection has been disposed.
Object name: 'Collection'.
   at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.ThrowContextDisposed()
   at Microsoft.AspNetCore.Http.DefaultHttpContext.get_Items()

Describe the bug

Access to HttpContext.Items is impossible on Apple devices.

Further technical details

  • ASP.NET Core 3.1
  • dotnet.info
.NET Core SDK (gemäß "global.json"):
 Version:   3.1.100
 Commit:    cd82f021f4

Laufzeitumgebung:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.100\

Host (useful for support):
  Version: 3.1.0
  Commit:  65f04fb6db

.NET Core SDKs installed:
  2.1.800-preview-009677 [C:\Program Files\dotnet\sdk]
  2.1.800-preview-009696 [C:\Program Files\dotnet\sdk]
  2.1.800 [C:\Program Files\dotnet\sdk]
  3.0.100-rc1-014190 [C:\Program Files\dotnet\sdk]
  3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  • VS 2019 16.5.0 Preview 1
@javiercn javiercn added area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer area-blazor Includes: Blazor, Razor Components and removed area-auth Includes: Authn, Authz, OAuth, OIDC, Bearer labels Dec 4, 2019
@javiercn
Copy link
Member

javiercn commented Dec 4, 2019

@sven5 thanks for contacting us.

Is that callstack inside the Blazor App? In general we don't recommend using the IHttpContextAccessor anywhere and it is not something that works with Signalr apps or Blazor apps for that matter.

I recommend you take a look at https://docs.microsoft.com/en-us/aspnet/core/security/blazor/?view=aspnetcore-3.1&tabs=visual-studio#authenticationstateprovider-service for tips on how to implement authentication/authorization in Blazor.

@sven5
Copy link
Author

sven5 commented Dec 4, 2019

@javiercn
Thanks for your support. I think that was the missing piece. I must've missed the AuthenticationStateProvider

Regards
Sven

@javiercn javiercn added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Dec 4, 2019
@javiercn javiercn closed this as completed Dec 4, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Jan 3, 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
Projects
None yet
Development

No branches or pull requests

2 participants