2014-02-13 125 views
1

我有使用MVC框架構建的asp.net網站。該網站使用IIS進行部署。該網站是http://smihit-reports.com/reporting。這是一個內部網站。我怎樣才能確保用戶是否把在http://smihit-reports.com/reportinghttp://smihit-reports.com它被引導到ASP.Net網站網址分辨率

+0

什麼*網頁*都是urls假設被重定向到? –

+0

當我輸入http://smihit-reports.com/reporting時,網站啓動正常。但我希望用戶輸入http://smihit-reports.com/或http://smihit-reports.com/reporting將其重定向到網站的主頁 – StackOverflowVeryHelpful

+0

您是否再次嘗試我的示例? (我做了一些改變) – djluis

回答

0

在同一頁面默認情況下http://smihit-reports.com/home等於http://smihit-reports.com,其中「家」是控制器的名稱。如果你想改變這種行爲,在默認情況下使用ReportingController而不是HomeController你應該去RouteConfig.cs類和更改

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}/{id}", 
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
); 

要:

routes.MapRoute(
    name: "Default", 
    url: "{controller}/{action}/{id}", 
    defaults: new { controller = "Reporting", action = "Index", id = UrlParameter.Optional } 
); 
+0

您是配置http://smihit-reports.com/報告爲默認頁面。 – djluis

+0

是的。並確保http://smihit-reports.com/reporting和http://smihit-reports.com被定向到同一頁面。 –

1

你有兩個選擇,我建議第一個:

您必須使用重定向,下面是一個示例: (請記住在路由頂部添加路由,以避免通用路由匹配。)

  1. 添加一個新的路由(在全球ASAX):

    routes.MapRoute(
        "Reporting Redirect", 
        "reporting", 
        new { controller = "Home", action = "Index" } 
    ); 
    
  2. 控制器重定向:

    公共類ReportingController:控制器 {

    public ActionResult Index() 
        { 
    
         return RedirectToAction("index", "home"); 
        } 
    } 
    

微軟MVC路由解釋here

+0

立即嘗試此操作。這有助於我獲得方向 – StackOverflowVeryHelpful

+0

對不起,我已經對我的代碼進行了一些更正,請你再試一次。 – djluis

+0

我認爲我的代碼存在一些問題。目前,即使在進行更改之後,我仍然需要訪問IIS 8網頁,而不是訪問我的主頁以獲取報告。 +1爲您的解決方案。它幫助我用我的代碼瞭解問題 – StackOverflowVeryHelpful