ASP.NET 中项目结构的最佳实践?
我正在开发一个 Web 应用程序,该应用程序很可能最终会产生大量 .aspx 和 .master 文件。尺寸更多的是范围问题而不是设计问题,所以这是不可避免的。大型项目的构建有什么好的/坏的做法吗?
显然,我有单独的目录来存放图像、脚本文件和样式表等资源,但是拥有一个用于母版页的文件夹会很疯狂吗?如果我知道我将有 50 或 60 个 aspx 页面,我是否应该只为 aspx 资源创建一个文件夹?更进一步,如果其中 10 个页面专用于单个产品,那么在我的 aspx 文件夹中为 ProductA 或其他内容创建一个文件夹是否明智?
一般来说,共识似乎是,无论什么方式对开发人员(在本例中是我)来说更具可读性都是好的,而且我知道 Visual Studio 在编译时无论如何都会做它自己的事情,但我一直处于下一个开发人员接手一个项目,所以如果可以的话,我希望避免看起来像个傻瓜。 (并不是说我希望很快就会出现“下一个开发人员”)
I'm working on a web application that is most likely going to end up with a large number of .aspx and .master files. The size is more a matter of scope than a design issue, so this is unavoidable. Are there any good/bad practices associated with the structuring of large projects?
Obviously I have separate directories for resources like Images, Script files, and Stylesheets, but would it be crazy to have a folder for master pages? If I know I'm going to have like 50 or 60 aspx pages, ought I to create a folder just for aspx resources? Taking that a step further, if 10 of those pages are going to be dedicated to a single product, would it be prudent to create a folder inside my aspx folder for ProductA or whatever?
Generally, the consensus seems to be that whatever makes it more readable to the developers (me, in this case) is good, and I know that Visual Studio does it's own thing when compiling anyways, but I've been in the shoes of the next developer to pick up a project so I'd like to avoid looking like a fool if I can. (not that I expect there to be a 'next developer' any time soon)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为母版页和产品特定页面创建文件夹没有任何问题。这只是一个偏好问题(除非您对 url 的外观有一些疯狂的要求)。
There's nothing wrong with creating folders for your master pages and product specific pages. It's simply a matter of preference (unless you have some crazy requirements for how the url should look).
对于诸如母版页之类的内容,这并不那么重要 - 这些内容本身并不能立即对客户可见,因此将它们放入子文件夹中是一项组织任务,您也可以这样做来帮助在您的头脑中构建网站。
然而,对于其他固定页面,文件夹的选择可能很重要;例如,如果您要执行以下操作:
http://www.mysite.com/folder/ thing.aspx
您现在已经为您的页面创建了一个上下文 - URL 实际上定义了该页面与您的网站的关系。此外,此上下文可以在导航和搜索引擎索引中发挥您的优势。
一个具体的例子是一个销售不同类别产品的网站;您可以将内容放入子文件夹中,例如:
http://www.mysite.com/books/list.aspx - 明确这是一个列出书籍的页面
http://www.mysite.com /games/list.aspx -明确这是一个列出游戏的页面,
然后搜索引擎将选择这些类别,您将能够通过以下方式链接到它们:
http://www.mysite.com/games/(假设您为该文件夹设置了默认页面)
实际上,您通过对功能所涉及的内容进行分类来分离您的功能。在上面的示例中,您还在您的网站和“游戏”之间建立了语义关系。
这是 REST 方法的一部分。
实际上,使用 URL 重写 这意味着,正如另一位发帖者所提到的,除了您自己的组织工作之外,您实际上并不需要担心结构。
这还意味着您可以减少页面数量,并根据您传递的 URL 加载用户控件和内容。
因此,请按照您想要的方式构建您的文件,但请考虑一下您网站的公众形象将是什么!
For things like Master Pages, it's not so important - these aren't immediately visible to clients in and of themselves, so putting them in a subfolder is an organizational task which you are doing to help structure the site in your head, too.
However, for other fixed pages, the choice of folder can be important; for example, if you were to do the following:
http://www.mysite.com/folder/thing.aspx
You have now created a context for your page - the URL is, in effect, defining how that page sits in relation to your site. Further, this context can be used to your advantage in both navigation and search engine indexing.
A concrete example is a site that sells different categories of products; you could put things in subfolders like:
http://www.mysite.com/books/list.aspx - clear that this is a page that lists books
http://www.mysite.com/games/list.aspx - clear that this is a page that lists games
Search engines will then pick up on these categories and you'll be able to link to them in ways like:
http://www.mysite.com/games/ (providing you set a default page for that folder)
In effect, you are segragating your functionality by categorizing what that functionality involves. You are also establishing a semantic relationship between your site and 'games' in the example above.
This is a part of the REST methodology.
In practice, it is much easier to achieve this sort of structure using URL Rewriting which means, as another poster has mentioned, you don't really need to worry about the structure, except for your own organizational efforts.
It also means you can cut down on the number of pages, and, instead load user controls and content based on the URL you are passed.
So structure your files anyway you want, but do think about what your site's public face will be!
我假设你使用的是asp.net网页而不是mvc???
对于您的 aspx 文件,我会将它们放在与服务目的相关的文件夹中。您说您将有 10 个特定于产品的 aspx 文件,因此创建一个或多个产品文件夹并将这些文件包含在该文件夹中。
aspx 文件的文件夹结构显然会控制地址栏中的路径,除非您打算进行大量路由。
我肯定会将您的母版页分成自己的文件夹,以保持整洁。如果母版页特定于您网站的某个部分(即:产品),请将其放在产品文件夹中。
I'm assuming you're using asp.net webpage rather than mvc???
for your aspx files, I would put them in folders relative to the purpose the serve. You say you'll have 10 aspx files specific to products, so create a product or products folder and have those contained within that folder.
The folder structure for your aspx files will obviously control the path in the address bar, unless you're planning to do a bunch of routing.
I would definitely separate your master pages into their own folder for keeping things neat. if a master page is specific to a section of your site (ie: products) put it within the product(s) folder.
您可以通过 Webform 使用路由。这意味着您现在可以做任何您想做的事情,并在需要时稍后修复它。网址不会改变。
You can use routing with webform. this mean that you can do whatever you want right now and fixing it later on if needed. url wont change.
显然,按部分/用途分隔页面和母版页没有任何问题。但是我想知道您是否不能通过使用更多用户控件、页面模板和主题来重用更多内容?
Obviously there's nothing wrong in separating pages and master pages by section/usage. However I'm wondering if you couldn't reuse more by using more User Controls, page templating and theming?