0

how to specify Route with static url having dot in it.

routes.MapRoute( "RouteForContentFolder", // Route name 
"Content/PDF/ABC.pdf", // URL with parameters 
new { controller = "User", action = "GetPdf"}// Parameter defaults 
); 

If i specify this route, it directly opens the PDF file without going through the controller and action.

I guess dot in ABC.pdf is the problem.

Can anybody tell me how to specidy dot '.' in static url.

I want this route to function only when the incoming url is

http://www.domainname.com/Content/PDF/ABC.pdf

Thanks in advance.

shakti
  • 191
  • 1
  • 8
  • 21
  • Worse case you take ABC.Pdf as a parameter to a PDF route and verify it in your controller method.. – Shane Courtrille May 21 '12 at 13:28
  • Are you saying that you have a static file "/content/pdf/abc.pdf"? If so, physical files will get served up FIRST before .NET attempts to match your requests to known routes. Rename or move your PDF file and the route will work. – Nick Bork May 21 '12 at 13:30
  • What is the objective of this URL, do you want to open the file after going through the Controller? – Tolio May 21 '12 at 13:48

1 Answers1

0

Route to your controller as you would normally do, then make your controller return the pdf.

Not very extensible to have a fixed route to a resource, imagine if you have two or 10 resources, how much routes to maintain.

Tolio
  • 1,023
  • 13
  • 30
  • hi, sorry but my concern is iam not able to route to my controller and action when the url is having . keyword in it like eg: http:domainname.com/Content/PDF/ABC.pdf – shakti May 21 '12 at 13:39
  • Ok, then you could receive the pdf filename as a parameter. "Content/PDF/{filename}" – Tolio May 21 '12 at 13:43
  • with that url, the debugger doesnt enter the controller and action method. it directly opens up the .pdf file. – shakti May 21 '12 at 13:45
  • You never answered my question, is "/content/pdf/abc.pdf" a physical file on the file system? – Nick Bork May 21 '12 at 13:47
  • @shakti you can refer to this stackoverflow question: [Dot character in ASP.NET MVC 3 route parameters](http://stackoverflow.com/questions/6534366/dot-character-in-asp-net-mvc-3-route-parameters) – Tolio May 21 '12 at 13:52
  • You can't create a Route that is the same path as a static file!!!!! The physical files will be served up first before any virtual files (routes) – Nick Bork May 21 '12 at 14:01
  • but i have specified routes.RouteExistingFiles = true; – shakti May 21 '12 at 14:10