Comments (7)
Solution: Create a Middleware and set string empty for User-Agent.
public class FixDetectionMiddleware
{
public FixDetectionMiddleware(RequestDelegate next)
{
_next = next;
}
readonly RequestDelegate _next;
public async Task Invoke(HttpContext context, IHostingEnvironment hostingEnviroment)
{
var userAgent = context.Request.Headers["User-Agent"].FirstOrDefault();
if (userAgent == null)
{
context.Request.Headers["User-Agent"] = string.Empty;
}
await _next.Invoke(context);
}
}
Startup
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseMiddleware<FixDetectionMiddleware>();
}
from wangkanai.
PR #85 merged and closing this issue.
from wangkanai.
I am also getting the same issue
Message=Exception : Object reference not set to an instance of an object.
Type : System.NullReferenceException
Source : Wangkanai.Detection.Browser
Stack Trace : at Wangkanai.Detection.Collections.InternetExplorer..ctor(String agent)
at Wangkanai.Detection.BrowserResolver.GetBrowser()
at Wangkanai.Detection.BrowserResolver..ctor(IUserAgentService service)
at lambda_method(Closure , ServiceProvider )
at Microsoft.Extensions.Internal.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d__6.MoveNext()
I think this line may be causing it in InternetExplorer.
_agent = agent.ToLower();
from wangkanai.
Why would the UserAgent be null? this is the web standard and also it in the test coverage that i wrote. #76
from wangkanai.
UserAgent is null when the request is from another API (not from the browser), for example:
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await _httpClient.GetAsync("/url/to/my/private/api");
from wangkanai.
Interesting, but REST is strictly HTTP and subject to RFC7231
So should you do add a useragent to the package header?
from wangkanai.
Yes, I could. But I have no control over another APIs (not mine) that consumes my API.
from wangkanai.
Related Issues (20)
- Remove external hard code from the repository HOT 1
- the Responsive didn't work HOT 1
- Wangkanai roadmap for .NET 7
- Wangkanai roadmap for .NET 8
- Wrapper project should be depreciate from the repo
- Code Coverage plan target
- Urgent: Optimize CI/CD for Faster, Efficient Builds and Boosted Morale! 🚀 HOT 3
- Directory.build.target for centralize package reference version control
- [Federation] Flexible Permission Authorization Policy
- [Federation] JSON Web Token Best Current Practices
- Build Props for .NET 8.0
- [Cryptography] List of hash
- [Cryptography] Fletcher's checksum
- [Cryptography] Rolling Hash
- [System] Throw If whitespace
- [Tabler] Blazor .NET 8.0 rc2 render mode entire app
- Central Package Management HOT 1
- Add support for detecting Edge on Android HOT 2
- Add support for detecting Windows 11 HOT 2
- Website link broken HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wangkanai.