如何检测新的 aspx 文件并从中获取信息?
我正在开发一个具有模块化部分的网站。我希望当一个新的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“标准”方法是您提到的配置文件,采用站点地图的形式。通过这样做,您将获得很多好的功能,例如面包屑等等。我知道这正是你要求不要得到的答案,但无论如何它就在那里。
不过,如果您坚持这样做,那么没有什么可以阻止您使用 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.