2011-11-25 96 views
0

我是新的論壇,也很新的MVC。 我有一個MVC應用程序,它在我的本地開發環境中測試時運行OK,但是當部署在IIS7上時,我遇到了一些問題,其中之一是在從查詢字符串中傳遞參數的控制器調用操作時出現404錯誤,「?」和「=」是由IIS編碼的,我想這就是它失敗的原因。 我的控制器動作:查詢字符串發送到MVC控制器得到編碼

public ActionResult CreateMenu() 
     { 
      MenuModel.MenuItem menuItem; 
      MenuModel.MenuItem childItem; 

      if (AuthenticationService.IsUserAuthenticated()) 
      { 
       string u_id = AuthenticationService.GetAuthenticatedUserName(); 
       Role u_role = Repository.GetUserRole(u_id); 

       mainMenu.MenuItems.RemoveAt(0); 
       if ((u_role.Role_Desc == "Administrator") || (u_role.Role_Desc == "Manager")) 
       { 
        int lastMenuNumber = mainMenu.MenuItems.Count; 
        menuItem = new MenuModel.MenuItem(++lastMenuNumber, "Account Settings", "", ""); 
        childItem = new MenuModel.MenuItem(++lastMenuNumber, "Log Report", "LogReporting", "ShowLog"); 
        menuItem.ChildItems.Add(childItem); 

        childItem = new MenuModel.MenuItem(++lastMenuNumber, "User Permissions", "PermissionsSetting", "ListPermissions"); 
        menuItem.ChildItems.Add(childItem); 

        mainMenu.MenuItems.Insert(0, menuItem); 
       } 
       // list of accessible BGs for selected client 

       var selectedClient = Session["client_Id"] != null ? 
             Repository.GetClientById((short)Session["client_Id"]) : 
             Repository.GetUserClients(u_id).First(); 

       int i = 0; 
       var bgs = Repository.GetUserClientAccesibleBusinessGroups(u_id, selectedClient.Client_ID); 
       if (bgs.Count() > 0) 
       { 
        foreach (var bg in bgs) 
        {                        

         menuItem = new MenuModel.MenuItem(mainMenu.MenuItems.Count + 1, bg.BG_Desc, "FtpAccess", String.Format("Group/{0}?cbg={1}", selectedClient.Client_ID, bg.Client_BG_ID)); 
         mainMenu.MenuItems.Insert(i++, menuItem); 
        } 
       } 
      } 

      ViewData.Model = mainMenu; 
      return View(); 
     } 

這在一個局部視圖<%Html.RenderAction使用( 「CreateMenu」, 「菜單」); %>在主視圖上顯示正確,但是當點擊一個項目時,結果是404錯誤。 我在web.config上更改的一件事是設置爲: requestValidationMode =「2.0」requestPathInvalidCharacters =「」 因爲我收到錯誤:從客戶端(?)檢測到潛在危險的Request.Path值,在添加了這些設置後,Request.Path錯誤消失,但現在我得到了404。 謝謝。

回答

0

你是Url.Encoding查詢字符串中的鍵/值?

HttpUtility.UrlEncode 

你能粘貼失敗的網址嗎?如果您未對其進行編碼(例如'/'),可能會導致問題,您可能在查詢字符串中包含一些無效字符。

+0

開發環境中的url:http:// localhost:53170/FtpAccess/Group/14?cbg = 19,在IIS服務器中將其變爲:http://someserver.int/FtpAccess/Group/14%253fcbg %3d19,IIS正在編碼字符「?」和「=」。在使用部署在服務器中的應用程序的web.config後,我仍然沒有運氣,但404錯過了,但出現了其他錯誤。 – user1058542