这是我第一次在IIS 7.X上部署asp.net mvc应用程序。
如果我在根路径上部署应用程序,那么它可以正常工作但如果我在非根路径上部署,如下所述,那么只有我的主页工作,其他任何链接都不起作用。
http://rootpath/MyApplication/
现在让我们说,我有控制器 - MyController和Action - MyAction。执行它时,我期待http://rootpath/MyApplication/MyController/MyAction但它只指向根路径。 (当前输出 - http://rootpath/MyController/MyAction)
我没有更改默认路由。我已使用“文件系统”选项发布了该站点。
/////// Code of Global.asax ///////
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
bool isBypassOn = false;
if (!isBypassOn)
{
//Following should be default application route path
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Login", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
else
{
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "ByPassLogin", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
}
//某些控制器代码
public class MemberHomeController:BaseController { // // GET:/ MemberHome /
public ActionResult Index()
{
//return Content("Successful Login...");
return View();
}
public override void Custom_OnLoad()
{
SelectedMenu = Menus.Home;
}
public ActionResult ScheduleIndex()
{
//return Content("Successful Login...");
return View();
}
}
答案 0 :(得分:0)
尝试
routes.MapRoute( "Default",
"MyApplication/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" } );
而不是默认值。