5
Hi,
Refer below link :-
https://stackoverflow.com/questions/39517816/how-to-ignore-routes-in-asp-net-core-1-0-1?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Hope it helps....
3
Thanks for replay @Jignesh Trivedi... I am not talking about authenticating.. There is a custom middleware which is not related to authentication... So sadly AllowAnonymous will not work here...
3
I am not sure but "AllowAnonymous" attribute can help you. Basically it ignore the Authentication for the route.
2
Hi,
Please refer below link. It may be helpful to you.
https://www.devtrends.co.uk/blog/conditional-middleware-based-on-request-in-asp.net-core
Thanks
Naimish
2
Probably you are looking for below with some regex
app.UseWhen(context=>!context.Request.Path.Value.ToLower().Trim().Contains(@"/route"), applicationBuilder =>
{
applicationBuilder.UseMiddleware<YourMiddleware>();
});
2
Thanks for replay Mr. Sagar... Provided link showing how to use middleware. Not helpful sorry!
1
Modify your VerifyClientMiddleware
to check the request path before performing the API key validation
public class VerifyClientMiddleware
{
private readonly RequestDelegate _next;
public VerifyClientMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
// Check if current path is allowed without API key
if (!_allowedPaths.Contains(context.Request.Path.Value))
{
// Perform your existing API key validation logic here (read and check API key)
// If key is invalid, throw an exception or return appropriate error response
}
// Call the next middleware in the pipeline
await _next(context);
}
}
1
private readonly string[] _allowedPaths = new string[] { "/user/authenticate", "/user/register" };
Create a string array or list to store the paths for unrestricted access (login and registration)
1
Check out this article on how to ignore routes conditionally
https://codetrojan.com/csharp/asp-net-core-how-to-restrict-specific-routes-from-middleware/