Search code examples
asp.netasp.net-mvcasp.net-mvc-4routeshttp-request

Catching all requests mvc 4


I have a folder with resources and I'd like to give opportunity to all users with right token get access it.Requests like:

 www.mysite.com/uploads/images?token = some security value

So I need to handle all requests that starts with

 www.mysite.com/uploads

chek for right token and approve or reject request.Could you give a basic example?


Solution

  • Why not just create a route for www.mysite.com/uploads/images/token?

            routes.MapRoute(
                "Uploads", // Route name
                "uploads/images/{token}", // URL with parameters
                new { controller = "uploads", action = "images", token = "" } // Parameter defaults
            );
        }
    

    This route should be placed at top of your route list and would catch route that starts with /uploads... Your users would be routed to uploadsController (in this case) and would execute the images Action Method passing Token as a string parameter.