3

ルート:

routes.MapRoute(
    "Customer_widget",
    "customer/widget/{action}/{id}",
    new { controller = "Customer_Widget", id = UrlParameter.Optional });

テスト URL1: (動作します) customer/widget/contact_list/1-1004-SC-0-0-0-0-0-0-Supplier-Supplier----0-0-0-0-Year-Calendar-0-Home-0

テスト URL2: (動作しません)

customer/widget/contact_list/1-1004-SC-0-0-0-0-0-0-Supplier-Supplier--6%2f1%2f2013-7%2f6%2f2013--0-0-0-0-Year-Calendar-0-Home-0  (does not work) 

上記の 2 つの URL の睾丸があります。最初の URL は適切な場所に移動します。しかし、2 番目の URL が道に迷いました...何が原因なのかわかりません...昼間の部分 6%2f1%2f2013-7%2f6%2f2013 が何らかの問題を引き起こしていると思いますが、よくわかりませんそれは何ですか。

カスタマーコントローラー

 public ActionResult Index(string id = null)
    {
      string temp = "~/customer/widget/contact_list/" + this.objURL.ToString();
      return Redirect("~/customer/widget/contact_list/" + this.objURL.ToString());
    }

Customer_WidgetController

  public ActionResult Contact_list(string id = null)
    {
      return PartialView("_contact_list",Customer_Widget.Contact_list.Load(id, ref errors));
    }

フロー CustomerController ->(マップ ルートによる) Customer_WidgetController

4

1 に答える 1

0

これはすべて、「/」に対応するエンコードされたスラッシュ「%2f」記号が原因です。このため、あなたのURL

customer/widget/contact_list/1-1004-SC-0-0-0-0-0-0-Supplier-Supplier--6%2f1%2f2013-7%2f6%2f2013--0-0-0-0-Year-Calendar-0-Home-0

8 つのセグメントに分割:

  1. お客様
  2. ウィジェット
  3. contact_list
  4. 1-1004-SC-0-0-0-0-0-0-Supplier-Supplier--6
  5. 1
  6. 2013年7月
  7. 6
  8. 2013--0-0-0-0-年-カレンダー-0-ホーム-0

しかし、あなたのルートでは4を期待しています。

セグメントの変数カウントを定義するには、次のようにアスタリスク (*) を使用できます。

routes.MapRoute(
    "Customer_widget",
    "customer/widget/{action}/{*id}",
    new { controller = "Customer_Widget", id = UrlParameter.Optional });

ルート システムはルートを順番にチェックします。したがって、これに注意して、このようなルートをできるだけ低く定義する必要があります。これは、このルートでキャッチしたくないリクエストをキャッチできるためです。たとえば、上記のルートの後に次のルートがシステムで定義される場合、それは決してキャッチされません:

routes.MapRoute(
        "Customer_widget",
        "customer/widget/{action}/{lang}/{*id}",
        new { controller = "Customer_Widget", lang = "en", id = UrlParameter.Optional }
        new { lang = "en|es|ru"});
于 2013-07-08T06:18:06.650 に答える