ASP.NET URL 重写,用于从不带扩展名的 URL 内容进行数据库查询
我正在尝试创建一个非常简单的 ASP.NET 应用程序,该应用程序以类似于 wiki 的方式显示根据 URL 从数据库检索的信息,但在本例中该站点是只读的。 我想要的 URL 示例如下:
http://www.foo.com/bar
然后,应用程序将使用“bar”作为 SQL 查询参数来显示数据库中与“bar”匹配的信息。
我已经研究了 IIS6 的许多 URL 重写器选项(这将在专用服务器上),但我仍然不确定该应用程序使用哪一个。
也许需要澄清的是,我只需要从单个 default.aspx
文件运行该网站,但我希望它按上述方式工作。 整个网站逻辑将会非常简单。
我希望在这一领域有更多经验的人可以帮助我——我正在寻找能够解决这一场景的最简单的解决方案。
I am trying to create a very simple ASP.NET application that presents information retrieved from a database based on the URL, in a similar way to a wiki, but in this case the site is read-only. An example of a URL I'd like would be:
http://www.foo.com/bar
The application would then use "bar" as a SQL query parameter to show information from the database that matches "bar".
I've looked into many URL re-writer options for IIS6 (and this would be on a dedicated server), but I'm still not sure which one to use for this application.
To perhaps clarify, I only need to run the site from a single default.aspx
file, but I want it to work as described above. The overall site logic will be very simple.
I am hoping that someone with more experience in this area can help me out -- I am looking for the simplest solution that will address this one scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果该扩展已注册,则 IIS6 仅将请求定向到 asp.net 引擎。 默认情况下,注册的扩展名是 aspx ascx asmx 等...
如果您无法基于查询字符串参数(例如 foo.com/default.aspx?query=bar)进行数据库查询,那么您在 IIS6 上可以做的最好的事情就是使用通配符映射。 基本上,这意味着每个请求都将定向到 asp.net(包括图像脚本和样式)。显然这会降低性能。
要启用通配符映射,请在 IIS 管理器中右键单击您的站点,然后转到“属性”->“ 主目录 -> 配置-> 底部的映射单击“插入”,然后输入 asp.net isapi dll 的路径(您可以从上面的 aspx 扩展名复制它),然后取消选中“验证该文件是否存在”。
进行更改后,您将能够请求 foo.com/bar
(另一种方法可能是向 foo.com/default.aspx/bar 发出请求)
IIS6 only directs requests to the asp.net engine if that extension has been registered. By default the registered extensions are aspx ascx asmx etc...
If you cannot base you database query on a query string parameter (e.g. foo.com/default.aspx?query=bar) then the best you can do on IIS6 is a wildcard mapping. Basically this means that every request will be directed over to asp.net (including images scripts and styles.) obviously this will degrade performance.
To enable wildcard mapping right click on your site in IIS manager and go to Properties -> Home Directory -> Configuration -> Mappings at the bottom click insert and type in the path to the asp.net isapi dll (you can copy it from the aspx extension above) and uncheck 'Verify that file exists'.
After making the changes you'll be able to request foo.com/bar
(another method might be to make a request to foo.com/default.aspx/bar)
仅供记录,IIS URL Rewrite 2 支持此功能,您可以安装包含数据库提供程序的可扩展性示例。 仅适用于 IIS 7+。
http://www.iis.net/download/urlrewrite
http://code.msdn.microsoft.com/rewriteextensibility
Just for the record, IIS URL Rewrite 2 supports this, you can install the extensibility samples that include a DB provider. Works on IIS 7+ only.
http://www.iis.net/download/urlrewrite
http://code.msdn.microsoft.com/rewriteextensibility