有没有办法在 WinForm/Console/VSTest 应用程序中使用 XmlSiteMapProvider?

发布于 2024-07-05 14:56:58 字数 515 浏览 6 评论 0原文

我想知道是否有一种解决方法可以在非 asp.net 应用程序中使用标准 XmlSiteMapProvider,例如 WinForm/Console,或者在我的例子中是 VS 单元测试。

以下代码失败,因为它无法在私有 GetConfigDocument 方法内创建指向 .sitemap 文件的路径。

XmlSiteMapProvider provider = new XmlSiteMapProvider();
NameValueCollection providerAttributes = new NameValueCollection();
providerAttributes.Add("siteMapFile", "Web.sitemap");
provider.Initialize("XmlSiteMapReader", providerAttributes);
provider.BuildSiteMap();

我觉得正确的解决方案是编写另一个提供程序。

I wonder whether there is a workaround for using the standard XmlSiteMapProvider within a non asp.net application, like WinForm/Console or, in my case, VS Unit Test one.

The following code fails, because it cannot create a path to the .sitemap file inside a private GetConfigDocument method.

XmlSiteMapProvider provider = new XmlSiteMapProvider();
NameValueCollection providerAttributes = new NameValueCollection();
providerAttributes.Add("siteMapFile", "Web.sitemap");
provider.Initialize("XmlSiteMapReader", providerAttributes);
provider.BuildSiteMap();

I feel the right solution is to write another provider.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

善良天后 2024-07-12 14:56:58

我不明白为什么不。 它只是一个实现接口的提供者。 您可能不需要很多功能,但您可以访问 API 以获取它为您提供的功能。 您的 WinForms 屏幕可以简单地使用 URL 进行识别,以便您可以确定您在层次结构中的位置。

您可能需要做的是创建提供程序的自定义实现,因为它将使用 HttpContext 获取当前 Web 请求的 Url 来识别当前位置,而您需要以不同方式获取该值。 这可能很棘手,因为您的 WinForm 应用程序可能会同时显示多个窗口。 如果您知道一次仅显示一个窗口,则可以使用在访问 SiteMap API 之前设置的静态值。

现在,如果您必须完成所有工作,那么您必须质疑使用 API 的价值。 可能没有足够的好处使其值得。

I do not see why not. It is just a provider that implements an interface. You may not need many of the features, but you can access the API for what it provides you. Your WinForms screens can simply use the Urls for identification so that you can determine your place in the hierarchy.

What you may have to do is create a custom implementation of the provider because it will use the HttpContext to get the Url of the current web request to identify current placement while you will need to get that value differently. That is what could be tricky because your WinForm application could be displaying multiple windows at time. If you know there is only one window showing at a time you could use a static value which is set prior to accessing the SiteMap API.

Now you have to question the value of using an API if you have to do all of the work. There may not be enough benefit to make it worthwhile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文