为静态资源 ASP.NET MVC 添加 MapRoute
我有一个 pdf 文件,我想为其创建一个路线图。有没有办法让对象默认采用 url 而不是操作控制器组合?
而不是
routes.MapRoute("MyRouteName", "MyNiceUrl", new { controller = "ControllerName", action = "ActionName" });
有类似的东西
routes.MapRoute("MyRouteName", "MyNiceUrl", new { relativeUrl="MyrelativeUrl" });
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" });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要静态资源的路由。您需要 url 帮助程序来引用它们:
如果您想要像
/SomeController/MyNiceUrl
这样的 url 来为您的 pdf 文件提供服务,您可以简单地编写一个控制器操作:然后:
You don't need routes for static resources. You need url helpers to reference them:
And if you wanted to have an url like
/SomeController/MyNiceUrl
to serve your pdf file you could simply write a controller action:and then:
正如这个答案中所示:
使用您的控制器,或创建一个迷你控制器,然后使用重定向ActionResult:
As in this answer:
Use your controller, or create a mini-controller, and then use the Redirect ActionResult: