2

カスタム ASP.NET サイトマップ プロバイダーを作成しましたが、うまく動作しますが、仮想パスにクエリ パラメーターを追加するとSiteMap.CurrentNodenullページが見つかりません。すべてのコードにブレークポイントを配置しましたが、クエリ パラメーターを使用して仮想パス プロバイダーに入力することは一度もありません。ここで何が欠けていますか?

4

1 に答える 1

2

質問に対する回答を見つけたので、後で使用するためにここに投稿します。サイトマップ プロバイダーは、一致するパスを検索するときに、常にクエリ文字列パラメーターのないパスを使用しているようです。トリックはReqest.RawUrl、オーバーライドされたSiteMapProvider.CurrentNode()関数で使用するのではなく、使用することRequest.Pathです。以下に私のソリューションを投稿しました:

public class CustomSiteMapProvider : SiteMapProvider {

    // Implement the CurrentNode property.
    public override SiteMapNode CurrentNode {
        get {
            var currentUrl = FindCurrentUrl();

            // Find the SiteMapNode that represents the current page.
            var currentNode = FindSiteMapNode(currentUrl);
            return currentNode;
        }
    }

    // Get the URL of the currently displayed page.
    string FindCurrentUrl() {
        try {
            // The current HttpContext.
            var currentContext = HttpContext.Current;

            if (currentContext != null) return currentContext.Request.Path;

            throw new Exception("HttpContext.Current is Invalid");

        } catch (Exception e) {
            throw new NotSupportedException("This provider requires a valid context.", e);
        }
    }
    ...
于 2014-10-02T19:30:30.933 に答える