Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Ignoring a request

$
0
0

I am trying to ignore request to certain routes. I tried writing a piece of custom middleware to handle this but I think its too late in the pipe line. It returns a blank page. I am creating an MVC app with siloed spa's. When the base route is requested it refreshes the page but with any additional url segments it ignores the request. This is what  tried that didn't work:

public class IgnoreClientRoutes
{
    private readonly RequestDelegate _next;
    private List<string> _baseRoutes;

    //base routes correcpond to Index actions of MVC controllers
    public IgnoreClientRoutes(RequestDelegate next, List<string> baseRoutes)
    {
        _next = next;
        _baseRoutes = baseRoutes;

     }//ctor


     public async Task Invoke(HttpContext context)
     {
        await Task.Run(() => {

            var path = context.Request.Path;

            foreach (var route in _baseRoutes)
            {
                Regex pattern = new Regex($"({route}).");
                if(pattern.IsMatch(path))
                {
                    //END RESPONSE HERE

                    return;

                }

            }

             _next(context);

        });



    }//Invoke()


}//class IgnoreClientRoutes

thanks in advance!


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>