You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've been using this library for a while in ASP.NET Web Forms, and it's been working great!
Recently we added WebApi endpoints into our Web Forms site as they are much nicer to work with than WebServices (See #24) and discovered some strange request scope behaviour. This likely also relates to #25.
It appears that the ASP.NET request scope != WebApi request scope, and also the WebApi request scope doesn't have the DefaultHttpContextAccessor.HttpContext configured (while the ASP.NET request scope does), this causes the The HttpContextBase has not been set for this Service Scope. exception to fire when using IHttpContextAccessor in a WebAPI controller.
Navigate to http://localhost:56145/api/test (WebAPI)
e.g. Throws exception HttpContextBase has not been set for this Service Scope
This is happening even though we have already created a TestObject for the request in Global.asmx.cs why are we making another one? Why is the IHttpContextAccessor not configured correctly? We have the same thread local HttpContext throughout.
Making TestObject [Context (Thread) Hashcode: 37460558]
Global [2021-11-11T20:47:17.8691440Z - [Instance: 6B37B561-49E6-432D-8DBB-D49364EEF978] [Context (DI) HashCode: 59487907] [Context (Thread) HashCode: 37460558]]
Making TestObject [Context (Thread) Hashcode: 37460558]
Exception thrown: 'System.InvalidOperationException' in AspNetDependencyInjection.dll
An exception of type 'System.InvalidOperationException' occurred in AspNetDependencyInjection.dll but was not handled in user code
The HttpContextBase has not been set for this Service Scope.
The text was updated successfully, but these errors were encountered:
nathanrobb
added a commit
to nathanrobb/AspNetDependencyInjectionWebServiceExample
that referenced
this issue
Nov 11, 2021
Hi Team,
We've been using this library for a while in ASP.NET Web Forms, and it's been working great!
Recently we added WebApi endpoints into our Web Forms site as they are much nicer to work with than
WebServices
(See #24) and discovered some strange request scope behaviour. This likely also relates to #25.It appears that the ASP.NET request scope != WebApi request scope, and also the WebApi request scope doesn't have the
DefaultHttpContextAccessor.HttpContext
configured (while the ASP.NET request scope does), this causes theThe HttpContextBase has not been set for this Service Scope.
exception to fire when usingIHttpContextAccessor
in a WebAPI controller.I have extended my minimal reproducing project here: https://github.com/nathanrobb/AspNetDependencyInjectionWebServiceExample to include our WebAPI issue outlined below.
This is using:
Jehoel.AspNetDependencyInjection
@5.0.0-beta2
Jehoel.AspNetDependencyInjection.WebApi
@5.0.0-beta2
To reproduce:
I am logging some hash codes to the
debugger
window. I would expect these hash codes to be equal for all operations within a request.http://localhost:56145/TestPage.aspx
(ASP page)http://localhost:56145/Test.asmx?op=HelloWorld
(WebService)http://localhost:56145/api/test
(WebAPI)HttpContextBase has not been set for this Service Scope
TestObject
for the request inGlobal.asmx.cs
why are we making another one? Why is theIHttpContextAccessor
not configured correctly? We have the same thread localHttpContext
throughout.The text was updated successfully, but these errors were encountered: