首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >asp.net mvc4路由配置

问asp.net mvc4路由配置
EN

Stack Overflow用户
提问于 2013-12-18 12:14:09
回答 2查看 253关注 0票数 0

我创建了一个非常简单的mvc4应用程序(visual的默认互联网应用程序)。这是我的RouteConfig课程:

代码语言:javascript
复制
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {

        routes.RouteExistingFiles = true;
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute("anyRoute", "content/themes/staticcontent.html", new { controller = "Account", action = "Register" });
        routes.IgnoreRoute("content/themes/{filename}.html");
    }
}

当输入url mySite.com/content/themes/staticcontent.html时,我希望用户被重定向到mySite.com/Account/Register,但我访问上述文件。

此外,除了staticcontent.html之外,我希望限制用户访问上述目录下的任何html文件,但我也可以访问该文件。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-03 08:48:23

也许您已经尝试过了,但是如果您将这两种语句倒置如下:

代码语言:javascript
复制
public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {

        routes.RouteExistingFiles = true;
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.IgnoreRoute("content/themes/{filename}.html");
        routes.MapRoute("anyRoute", "content/themes/staticcontent.html", new { controller = "Account", action = "Register" });
    }
}
票数 1
EN

Stack Overflow用户

发布于 2014-04-03 09:25:56

默认情况下,ASP.NET MVC路由不处理.html文件。您需要先在IIS中设置它(请参阅http://weblogs.asp.net/jgalloway/archive/2013/08/29/asp-net-mvc-routing-intercepting-file-requests-like-index-html-and-what-it-teaches-about-how-routing-works.aspx),然后再进行路由。

如果它只是一个需要重定向的文件,那么最简单的方法就是在IIS中设置301或302重定向。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20657941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档