iis-6 - ASP.NET 中的 URL 重写而不重定向

标签 iis-6 url-rewriting asp.net-2.0

我们有一个 CMS 系统,可以创建带有许多参数的长 URL。我们希望改变它们的呈现方式,使它们更加友好。
由于我们已经在这个 CMS 上构建了许多网站,因此重写 CMS 以创建友好的 url 有点困难(尽管这是我们正在考虑的方法,如果没有找到替代方案),我们正在寻找一种方法,当用户点击长网址,该网址将在浏览器中更改为友好网址 - 不使用 Response.Redirect()
在Wordpress中存在这样的方法(我不确定它是在代码中还是在Apache中完成),并且我想知道它是否也可以在ASP.NET 2.0中完成。
另一件需要考虑的事情是,url 之间的更改必须通过访问数据库来完成。
更新:我们正在使用 IIS6

最佳答案

如果您使用 ii7,最简单的方法是使用 URL Rewrite Module根据该链接您可以

Define powerful rules to transform complex URLs into simple and consistent Web addresses

URL Rewrite allows Web administrators to easily build powerful rules using rewrite providers written in .NET, regular expression pattern matching, and wildcard mapping to examine information in both URLs and other HTTP headers and IIS server variables. Rules can be written to generate URLs that can be easier for users to remember, simple for search engines to index, and allow URLs to follow a consistent and canonical host name format. URL Rewrite further simplifies the rule creation process with support for content rewriting, rule templates, rewrite maps, rule validation, and import of existing mod_rewrite rules.

否则,您将必须使用 Andrew M 描述的技术或使用 Response.Redirect。无论如何,我相当确定所有这些方法都会产生 http 301 响应。我提到这一点是因为不清楚为什么您不想执行 Response.Redirect。这是编码限制吗?

更新 由于您使用的是 IIS 6,因此您需要使用另一种方法进行 URL 重写。

This Article Scott Mitchell 详细介绍了如何做到这一点。

Implementing URL Rewriting

URL rewriting can be implemented either with ISAPI filters at the IIS Web server level, or with either HTTP modules or HTTP handlers at the ASP.NET level. This article focuses on implementing URL rewriting with ASP.NET, so we won't be delving into the specifics of implementing URL rewriting with ISAPI filters. There are, however, numerous third-party ISAPI filters available for URL rewriting, such as:

ISAPI Rewrite

IIS Rewrite

PageXChanger

And many others!

本文继续描述如何实现 HTTP 模块或处理程序。

性能 重定向响应 HTTP 301 通常仅包含 < 1K 的少量数据。因此,如果它很引人注目,我会感到惊讶。 例如,这些网址的页面加载差异并不明显

"https://stackoverflow.com/q/4144940/119477"

"https://stackoverflow.com/questions/4144940/url-rewrite-without-redirect-in-asp-net"

(我已经使用 ieHTTPHeaders 确认 http 301 是用于更改 URL 的)

网页排名

This is Google 的网站站长中心网站对 301 有何评论。

If you need to change the URL of a page as it is shown in search engine results, we recommended that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page.

关于iis-6 - ASP.NET 中的 URL 重写而不重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4144940/

相关文章:

c# - 在 IIS 7.5 上通过代理调用 WCF 时出现身份验证问题

iis-6 - 以编程方式从配置数据库 IIS6 中删除 etag 后缀(更改编号)

jquery - URL 重写 - 删除哈希值

javascript - 我们可以在 Magento 中覆盖核心 js 文件吗?

oracle - 从 IIS 托管的 Web 应用程序连接到 Oracle 时出现 "Unhandled Execution Error"

c# - 手动增加新行的 PK 时如何避免数据库竞争条件

.net - 使 asp.net 应用程序符合 IPv6

php - 使用 htaccess 生成 seo 友好的 url

asp.net - ASP.NET 页面中的 `CodeFile` 属性有什么用

asp.net - IIS6 SSL 配置 - 必须登录两次(一次用于 :80, 一次用于:443)