如何在 ASP.NET 而不是 ASP.NET MVC 中创建博客
我使用 ASP.NET MVC 和 MSSQL 创建了一个博客应用程序。我必须说,我真的很喜欢使用 ASP.NET MVC 创建应用程序的过程。 Clean URLS(带 URL 路由)、无视图状态等。
但我想知道如果我选择网络表单样式编码,这将如何完成?当我创建一篇文章时,aspx 会立即创建吗?(以这个 url 为例: http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack -asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx)虽然 URL 不干净,但仍然有意义。如果是的话那么它对应的cs文件呢?如果不是的话,网址怎么这么干净?
如果有人能解释一下它是如何在 ASP.NET 中完成的,那就太好了。
谢谢你,法拉兹。
I have created a blog application with ASP.NET MVC and MSSQL. I must say, i really enjoyed the process of creating an application with ASP.NET MVC. Clean URLS(with URL routing), No view States and so on.
BUT i was wondering how would this would have been done if i choose web-form style coding? will the aspx would be created in the fly as i create a article.(take this url for ex: http://weblogs.asp.net/scottgu/archive/2010/10/06/announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx) though the URL is not clean but still makes sense. if yes then what about its corresponding cs file? if no how is the URL so clean?
Would be great if someone throw some light on how it is done in ASP.NET.
Thank you, Faraaz.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用 .NET 4,则可以使用
MapPageRoute
通过常规 Web 表单完成干净的 URL。添加
MapPageRoute
后,您不再有“我应该使用 ASP.NET MVC 因为我想要干净的 URL”的感觉。如果您喜欢这种模式,请选择 ASP.NET MVC。如果您习惯使用 Web 表单,请使用它 - 并使用
MapPageRoute
来实现干净的 URL(如果 <= .NET 4,则使用 URL 重写模块)If your using .NET 4, you can make use of
MapPageRoute
to accomplish the clean URL's with regular Web Forms.With the addition of
MapPageRoute
, you no longer have the feeling "I should use ASP.NET MVC because i want clean URL's".Choose ASP.NET MVC if you like the pattern. If your used to Web Forms, use it - and use
MapPageRoute
to achieve clean URL's (or use a URL Rewriting module if <= .NET 4)ASP .NET 中的博客将以大致相同的方式完成。这个想法是使用一个文件和 URL 重写。 IIS7 内置了 URL 重写功能,但对于 IIS6,您可以使用 ISAPI_Rewrite 之类的东西来处理 .htaccess 样式文件( Apache 使用的就是这个)。
ASP .NET MVC 在其路由中为您处理所有这些,但您可以使用 URL 重写工具自己完成。不同之处在于,对于 MVC,应用程序处理重写,但 ISAPI_Rewrite、IIS 重写由服务器完成。这可以将 http://mysite.com/something/other 之类的 URL 更改为 http://mysite.com/file.asp?p1=something&p2=other。
第二个链接仅是服务器内部的(它实际上不会更改用户地址栏中的 URL)。对于 Scott 博客上的 URL,您可以将“announcing-nupack-asp...”位作为文章行的一部分存储在数据库中,以便您的博客文章页面有需要查找的内容。这些文件实际上并不存在于服务器上,但重写会将所有请求传递到带有参数的现有文件。
请注意,这种技术对于许多不同的网站都很常见 - 不仅仅是博客。请注意 Stack Overflow URL、Twitter URL 等。MSDN
有一篇关于 URL 重写的旧文章在 ASP .NET 中,以及一些可以使用的过滤器示例。
A blog in ASP .NET would have been done in much the same way. The idea is to use one file and URL rewriting. IIS7 has URL rewriting built in but for IIS6 you can use something like ISAPI_Rewrite to handle .htaccess style files (which is what Apache uses).
ASP .NET MVC handles all this for you in its routing but you can do it yourself using a URL rewriting tool. The difference is that for MVC, the application handles the rewriting but ISAPI_Rewrite, IIS Rewriting are done by the server. This can change a URL like http://mysite.com/something/other to http://mysite.com/file.asp?p1=something&p2=other.
The second link is only internal to the server (it doesn't actually change the URL in the user's address bar). In the case of a URL like on Scott's blog, you could store the 'announcing-nupack-asp...' bit in a database as part of the article row so your blog article page has something to look for. The files don't actually exist on the server but the rewriting passes all requests to an existing file with parameters.
Note that this technique is common for lots of different sites - not just blogs. Notice the Stack Overflow URL, Twitter URLs, etc.
MSDN has an old article on URL Rewriting in ASP .NET, along with some examples of filters you can use.
请参阅 IIS URL 重写模块
See IIS URL Rewrite Module
如果您使用 .Net Framework 3.5 SP1(如果您无权访问 .Net 4),则可以将 asp.net MVC 中的 URL 重写与 WebForms 一起使用
。 microsoft.com/en-us/magazine/dd347546.aspx" rel="nofollow">MSDN 杂志文章解释...
You can use the URL Rewriting that is in asp.net MVC with WebForms if you are using .Net Framework 3.5 SP1 (if you don't have access to .Net 4)
Here's an MSDN magazine article explaning...