我有我的MVC
项目中的下列控制器:使路由工作而不指定URL中的操作名称。 - 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'控制器在默认值之前先评估。 –