I have created following middleware in ASP.NET Core WebAPI project.
SignalrQsHeaderMiddleware.cs
public class SignalrQsHeaderMiddleware
{
private readonly RequestDelegate _next;
public SignalrQsHeaderMiddleware(RequestDelegate next)
{
this._next = next;
}
public async Task Invoke(HttpContext context)
{
/*
if (context.Request.Path.Value.Contains("/restaurantHub"))
{
var qsHeader = context.Request.Query["access_token"].ToString();
if (!qsHeader.IsNullOrEmpty())
{
context.Request.Headers.Add("Authorization",qsHeader);
}
}*/
await _next.Invoke(context);
}
}
In Startup.cs added following line.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//Other services.
app.UseMiddleware<SignalrQsHeaderMiddleware>();//<-- added here
}
And when i run project following error occur.
The 'Invoke' method's first argument must be of type 'HttpContext'. at Microsoft.AspNetCore.Builder.<>c__DisplayClass3_0.b__0(RequestDelegate next) at Microsoft.AspNetCore.Builder.Internal.ApplicationBuilder.Build() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Note: I have try this solution Here
But still i am facing the same issue.
Any suggestion what i am doing wrong ?

Microsoft.AspNetCore.Http. Now it's working fine. :)await _next(context)?