Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing static files in ASP.NET MVC 3 like robots.txt

I would like to have the following link "http://mywebsite.com/robots.txt" linked to a static file ~/Content/robots.txt.

How can I do this?

Thanks, Merijn

like image 239
Merijn Avatar asked Nov 24 '11 14:11

Merijn


People also ask

What are static files in MVC?

Host static files in ASP.NET MVC ASP.NET MVC supports placing static files side by side with files that should be kept private on the server. IIS and ASP.NET require explicitly restricting certain files or file extensions from being served from the folder in which an ASP.NET app is hosted.

How many routes are there in MVC?

ASP.NET MVC offers two approaches to routing: The route table, which is a collection of routes that can be used to match incoming requests to controller actions.

Can we have multiple routing in MVC?

Multiple Routes You need to provide at least two parameters in MapRoute, route name, and URL pattern. The Defaults parameter is optional. You can register multiple custom routes with different names.


1 Answers

Adding a route like this should do the trick. This way any static .txt file like robots.txt can be served.

routes.IgnoreRoute("{resource}.txt"); 
like image 147
James Lawruk Avatar answered Oct 15 '22 16:10

James Lawruk