ASP.NET MVC路由开始在html页面 [英] ASP.NET MVC Routing to start at html page

查看:138
本文介绍了ASP.NET MVC路由开始在html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IIS 6,我想我的问题是,我不知道如何路由使用routes.MapRoute非控制器。

I am using IIS 6. I think my problem is that I don't know how to route to a non controller using the routes.MapRoute.

我有一个网址,例如example.com和我希望它成为的index.htm页面,而不是使用MVC。我该如何设置?在IIS中,我的index.htm作为我做起文件,我的global.asax有标准默认的路由,它调用主页/索引。

I have a url such as example.com and I want it to serve the index.htm page and not use the MVC. how do I set that up? In IIS, I have index.htm as my start document and my global.asax has the standard "default" routing, where it calls the Home/Index.

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

我添加了这个:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        if (Context.Request.FilePath == "/") Context.RewritePath("index.htm");
    }

它的工作原理。但是,这是最好的解决办法?

it works. But is this the best solution?

推荐答案

我添加了一个虚拟控制器指定的Web站点的根目录时,作为默认的控制器使用。该控制器具有一个单一的指标作用,在根部做重定向到的index.htm网站。

I added a dummy controller to use as the default controller when the root of the web site is specified. This controller has a single index action that does a redirect to the index.htm site at the root.

public class DocumentationController : Controller
{
    public ActionResult Index()
    {
        return Redirect( Url.Content( "~/index.htm" ) );
    }

}

请注意,我使用这个基于MVC的REST Web服务的文档。如果你去的网站的根,你得到的服务,而不是一些默认的Web服务方法的文档。

Note that I'm using this a the documentation of an MVC-based REST web service. If you go to the root of the site, you get the documentation of the service instead of some default web service method.

这篇关于ASP.NET MVC路由开始在html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆