如何检测新的 aspx 文件并从中获取信息?

发布于 2024-09-11 08:49:27 字数 228 浏览 4 评论 0原文

我正在开发一个具有模块化部分的网站。我希望当一个新的 aspx (和 aspx.cs)文件被放置在应用程序的子目录中时,我可以向类询问一些信息......

这个想法是,当文件被放置在目录中时,会出现一个新菜单项目已添加到菜单中。为此,我需要“询问类”的名称、图标、描述等。

有没有办法确定代码隐藏文件中定义的类并实例化它的实例?

我知道我可以查找并解析每个插件的配置文件,但我宁愿不必走这条路。

I'm developing a website that has modular section. I would like it that when a new aspx (and aspx.cs) file is placed in a subdirectory of the application that I can ask the class some information...

The idea is that when the file is placed in the directory a new menu item is added to the menu. To do that I need to "ask the class" for its name, icon, description, etc.

Is there a way to determine the class that is defined in codebehind file and to instantiate an instance of it?

I know I could look for and parse a config file for each plugin but I would rather not have to go that route.

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

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

发布评论

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

评论(1

祁梦 2024-09-18 08:49:27

“标准”方法是您提到的配置文件,采用站点地图的形式。通过这样做,您将获得很多好的功能,例如面包屑等等。我知道这正是你要求不要得到的答案,但无论如何它就在那里。

不过,如果您坚持这样做,那么没有什么可以阻止您使用 MapPath 并实际在磁盘中搜索 .aspx 文件,解析它们以提取某些信息(例如类名),然后执行您喜欢的任何操作。

但 SiteMap 更好,除非你有一些非常奇怪的需求。请注意,您的站点地图可以来自数据库或其他动态源,它不必是 XML 文件。

The "standard" method for this is the config file you mention, in the form of a Sitemap. You'll get a lot of good features out of it by doing it that way, like breadcrumbs and so forth. I know this is exactly the answer you asked not to get, but there it is anyway.

If you insist, though, there's nothing stopping you from using MapPath and actually searching the disk for .aspx files, parsing them to pull out certain info (like class name), and then doing whatever you like.

But SiteMap is better, unless you have some very strange requirement. Note that your sitemap can come from a database or another dynamic source, it doesn't have to be an XML file.

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