比如我输入:
http://www.test.com/
http://www.test.com/1/
http://www.test.com/blog/post
则分别访问以下页面:
~/html/www.test.com/index.html
~/html/www.test.com/1/index.html
~/html/www.test.com/blog/post.aspx请知道的大侠顺便给出示例router的示例,多谢!
http://www.test.com/
http://www.test.com/1/
http://www.test.com/blog/post
则分别访问以下页面:
~/html/www.test.com/index.html
~/html/www.test.com/1/index.html
~/html/www.test.com/blog/post.aspx请知道的大侠顺便给出示例router的示例,多谢!
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;namespace MvcApplication1
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801 public class MvcApplication : System.Web.HttpApplication
{
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 = UrlParameter.Optional } // Parameter defaults
); ViewEngines.Engines.Add(new WebFormViewEngine()
{
ViewLocationFormats = new string[] { "~/html/www.test.com/{1}/{0}.aspx" }
}); } protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes);
}
}
}
输入http://www.a.com/1访问的实际文件地址是http://www.a.com/html/www_a_com/1/index.html
输入http://www.a.com/blog/post访问的实际文件地址是http://www.a.com/html/www_a_com/blog/post.aspx输入http://www.b.com/访问的实际文件地址是http://www.b.com/html/www_b_com/index.html
输入http://www.b.com/1访问的实际文件地址是http://www.b.com/html/www_b_com/1/index.html
输入http://www.b.com/blog/post访问的实际文件地址是http://www.b.com/html/www_b_com/blog/post.aspx
ASP.NET MVC 是一个包含大量约定的 MVC 框架。
它的目标是,实现约定优于配置(CoC)的价值观,也就是如果你认可它的约定,它可以大大简化你的工作,否则,使用ASP.NET MVC还不如不用它。