asp.net-mvc – ASP.NET MVC路由从html页面开始
发布时间:2020-05-28 07:02:12 所属栏目:asp.Net 来源:互联网
导读:我正在使用IIS 6.我想我的问题是我不知道如何使用routes.MapRoute路由到一个非控制器. 我有一个url,如example.com,我希望它为index.htm页面提供服务,而不是使用MVC.我该如何设定?在IIS中,我将index.htm作为我的起始文档,我的global.asax具有标准的“默认”路
|
我正在使用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服务方法. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – Asp.net内核MVC post参数始终为null
- asp.net-mvc – ASP.NET MVC中UpdateModel的正确行为是什么
- asp.net – 考虑Scalablity和友好URL的GUID替代方案
- ASP.net WebForms – 构造函数与Page_Load
- asp.net-mvc-3 – DotNetOpenAuth.Asp在MVC4应用程序单元测
- asp.net-mvc – 使JSON.NET和Serializable属性一起工作
- asp.net – 为什么在添加新的响应标头时会出现“平台不支持
- asp.net – 为什么要模拟HttpContext,如果它可以构造?
- asp.net – 如何在主页面中包含CSS?
- asp.net-mvc-2 – 我应该在我的MVC视图中使用Url.Content()
推荐文章
站长推荐
- 从ASP.Net MVC访问Active Directory使用C#
- 如何在ASP.NET中混合WebForms和MVC
- asp.net – 使用Global.asax有什么优点和缺点?
- asp.net – 无法从HRESULT加载文件或程序集异常:
- asp.net-mvc – mvc razor @helper可以返回非编码
- asp.net-mvc – 如何使用asp.net mvc razor在视图
- asp.net-mvc – 使用WebForm的MVC HtmlHelper
- asp.net-mvc – asp.net mvc – 子文件夹
- asp.net-mvc – 了解nopCommerce的MVC标签
- asp.net – IIS Express安装目录在哪里?
热点阅读
