0

データベースから URL を動的に取得し、それを 1 つのコントローラーで複数のルートに渡します。そしてViewのモデルにurl-itemsのコンテンツ本体を入れると。そしてポイントは、編集済みプロジェクトをコンパイルした後にのみ新しいページの読み込みを開始することです.404ページを表示する前に.

public class DynamicController : MenuController
{
    //
    // GET: /Dynamic/
   s

    public  ActionResult Indexx(string routes) {
        var str = service.Get().Single(x=>x.Url==routes);

        return View(str);
    }


}

ルート:

     routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
      /**/  IMenuService<Menu> service = new MenuEntityService();
      foreach (var item in service.Get())
      {
          routes.MapRoute(
          name: item.Url,
          url: item.Url,
          defaults: new { controller = "Dynamic", action = "Indexx",routes=item.Url },
          namespaces: new[] { "MvcApplication1.Controllers" }
          );
      }
4

2 に答える 2

0

私はこれで答えを見つけました:HttpRuntime.UnloadAppDomain();メニュー項目を作成するコントローラーアクションに書きました

于 2013-06-12T19:37:12.960 に答える
0

ルート登録はApplication_Startイベント時のみとなります。このイベントは、アプリケーションのライフサイクル中に 1 回だけ発生します。

したがって、作成された各動的パスのルートを作成するには、アプリケーション プールを再起動する必要があります。(したがって、アプリケーションプールが自動的に再起動されるため、再コンパイル/デプロイ後にルートが機能するのはなぜですか)

新しい動的パスが作成されるたびにアプリケーション プールを再起動する必要がないようにするには、これらの動的ページを処理するためのキャッチ オール/デフォルト ルートを作成することをお勧めします。

//this catches all  requests
routes.MapRoute(
    "Dynamic page route",
    "{*routes}",
     new { controller = "Dynamic", action = "Indexx" } 
);
于 2013-06-11T00:32:29.163 に答える