我正在使用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
);
}
Run Code Online (Sandbox Code Playgroud)
我补充说:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath == "/") Context.RewritePath("index.htm");
}
Run Code Online (Sandbox Code Playgroud)
有用.但这是最好的解决方案吗?
tva*_*son 19
我添加了一个虚拟控制器,用作指定网站根目录时的默认控制器.此控制器具有单个索引操作,该操作将重定向到根目录下的index.htm站点.
public class DocumentationController : Controller
{
public ActionResult Index()
{
return Redirect( Url.Content( "~/index.htm" ) );
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,我使用的是基于MVC的REST Web服务的文档.如果您转到站点的根目录,则会获得该服务的文档,而不是某些默认的Web服务方法.
配置asp.net路由以忽略root ("/") requests
并让IIS's "Default Document"
ISAPI过滤器提供静态index.htm
文件
将以下内容添加到RegisterRoutes
方法中.
routes.IgnoreRoute("");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18268 次 |
最近记录: |