2011-04-19 73 views
0

我有一個MVC和Asp.net混合應用程序我有一個控制器,但它沒有任何家庭控制器,我不想從MVC視圖啓動應用程序我需要從default.aspx開始MVC和Asp.net混合應用程序的起點

當我在url結尾處寫入「default.aspx」時,它工作正常。但它不起作用,當我寫mysite.com/

另外我有一個web服務,但它現在不工作。因爲路由如:「mywebservice.asmx/mymethodname」

如何設置我的global.asax?我需要在這個組合中運行什麼配置?

回答

0

你可以只在您的Web應用程序的子文件夾中創建你的MVC應用程序,然後移動任何Global.asax中配置你的Web窗體應用程序

你只需要更新你的路由,如果你的MVC應用程序的創建一個名爲MVC的文件夾中,可能是這個樣子:

  routes.MapRoute(
      "MVC default",            
      "MVC/default.aspx",           
      new { controller = "Home", action = "Index", id = "" } 
     ); 

     routes.MapRoute(
      "Services", 
      "MVC/{controller}/{action}/{id}", 
      new { controller = "Home", action = "Index", id = "" } 
      ); 

編輯:

其實你需要映射確保您的意見是正確映射也一樣,你可以通過創建一個快速自定義視圖引擎做到這一點:

 public class CustomViewEngine : System.Web.Mvc.WebFormViewEngine 
{ 
    public CustomViewEngine() 
    { 
     base.ViewLocationFormats = new string[] 
     { 
      "~/MVC/Views/{1}/{0}.aspx", 
      "~/MVC/Views/{1}/{0}.ascx", 
      "~/MVC/Views/Shared/{0}.aspx", 
      "~/MVC/Views/Shared/{0}.ascx" 
     }; 

      base.PartialViewLocationFormats = new string[] { 
     "~/MVC/Views/{1}/{0}.aspx", 
      "~/MVC/Views/{1}/{0}.ascx", 
      "~/MVC/Views/Shared/{0}.aspx", 
      "~/MVC/Views/Shared/{0}.ascx" 
     }; 

      base.MasterLocationFormats = new string[] 
     { 
      "~/MVC/Views/{1}/{0}.master", 
      "~/MVC/Views/Shared/{0}.master" 
     }; 
    } 

} 

,然後登記在您的Global.asax:

 System.Web.Mvc.ViewEngines.Engines.Clear(); 
     System.Web.Mvc.ViewEngines.Engines.Add(new CustomViewEngine());