1

I have a pdf file which I would like to a create a route map for it. Is there a way to make object default take a url in stead of action controller combination?

Instead of

 routes.MapRoute("MyRouteName", "MyNiceUrl", new { controller = "ControllerName", action = "ActionName" });

Have something like

 routes.MapRoute("MyRouteName", "MyNiceUrl", new { relativeUrl="MyrelativeUrl" });
Emmanuel N
  • 7,350
  • 2
  • 26
  • 36

2 Answers2

2

You don't need routes for static resources. You need url helpers to reference them:

<a href="<%= Url.Content("~/Content/test.pdf") %>">Download pdf</a>

And if you wanted to have an url like /SomeController/MyNiceUrl to serve your pdf file you could simply write a controller action:

public ActionResult MyNiceUrl()
{
    var pdf = Server.MapPath("~/Content/test.pdf");
    return File(pdf, "application/pdf");
}

and then:

<%= Html.ActionLink("Download pdf", "MyNiceUrl", "SomeController") %>
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

As in this answer:

Use your controller, or create a mini-controller, and then use the Redirect ActionResult:

public class MyController : Controller
{
    public ActionResult Pdf()
    {
        return Redirect( Url.Content( "mydoc.pdf" ) );
    }

}
Community
  • 1
  • 1
Chris Jaynes
  • 2,868
  • 30
  • 29