asp.net-mvc – ASP.NET MVC路由从html页面开始

我正在使用IIS 6.我想我的问题是我不知道如何使用routes.MapRoute路由到一个非控制器.

我有一个url,如example.com,我希望它为index.htm页面提供服务,而不是使用MVC.我该如何设定?在IIS中,我将index.htm作为我的起始文档,我的global.asax具有标准的“认”路由,其中​​它调用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");
    }

有用.但这是最好的解决方案吗?

解决方法

当指定网站的根目录时,我添加一个虚拟控制器作为认控制器.该控制器具有单个索引操作,该索引操作将重定向到根的index.htm站点.
public class DocumentationController : Controller
{
    public ActionResult Index()
    {
        return Redirect( Url.Content( "~/index.htm" ) );
    }

}

请注意,我使用的是基于MVC的REST Web服务的文档.如果您访问该站点的根目录,您将获得该服务的文档,而不是一些认的Web服务方法.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....