【发布时间】:2017-09-23 04:55:34
【问题描述】:
我的MVC 项目中有以下控制器:
public class PressController : Controller
{
// GET: Press
public ActionResult Index()
{
return File("../press/FFF_PRESS.zip", ".zip");
}
}
我的路线
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
当我加载网站时,我的网址如下:
www.example.com
当我点击以下Action<li class="footer__navEl"><a href='@Url.Action("Index", "Press")'>PRESS</a></li>时正确显示主页
我希望网址是
www.example.com/press
并返回 zip 文件。
但是,当我单击此 Action 时,我得到以下信息:
HTTP 错误 403.14 - 禁止 Web 服务器配置为不列出此目录的内容。
当我指定时
www.example.com/press/index
正确返回 .zip 文件。
现在我在 routes.config 中添加了以下内容:
routes.MapRoute("Press", "Press", new { controller = "Press", action = "Index" });
我仍然遇到上述相同的错误,有人可以解释一下我可能缺少什么以使其正确执行吗?
【问题讨论】:
-
你设置
MapRoute的顺序正确吗?[domain]/Press将请求显示Press目录内容,默认情况下在 IIS 中禁用。应该调整路由顺序或格式,以便Press控制器在默认值之前首先评估。
标签: asp.net asp.net-mvc routes url-routing asp.net-mvc-routing