【问题标题】:How to deal with extensionless Url in ASP.Net and IIS6如何处理 ASP.Net 和 IIS6 中的无扩展 URL
【发布时间】:2012-05-28 18:28:57
【问题描述】:
我需要一种编写无扩展名网址的方法。我的服务器是 IIS6.0 版本 1 的共享主机。目前我正在使用 UrlRewriting.Net dll,它仅支持 IIS7。
我的原始网址是 abc.xyz.in/Index.aspx?c=comp_Name;
我的虚拟网址是 abc.xyz.in/comp_Name.aspx 但我希望它是 abc.xyz.in/comp_Name
是否可以通过任何其他模块或任何东西。请注意我的主机是共享主机。所以我既不能自己配置 IIS,也不能强迫我的管理员对其进行修改。
【问题讨论】:
标签:
c#
asp.net
url-rewriting
【解决方案1】:
在 IIS6(和旧版本)中自定义路由的问题是它们默认不调用 ASP.Net 模块,除非您请求 .aspx、.ashx、.asmx 文件。有一些解决方案使用自定义错误来检查您尝试访问的内容,然后显示正确的页面,但这不是一个很好的解决方案(但如果您真的想了解更多关于它的信息,这里有一个示例在 CodeProject:http://www.codeproject.com/Articles/44475/IIS-vs-ASP-NET-URL-Rewriting)。
我的建议是让您的网络主机为 ASP.Net 添加一个通配符映射,以便它处理所有传入您网站的请求,这样您就可以编写一个适当的路由模块,他们可能不必这样做,但在问,它可以很容易地在一个站点的基础上设置。如果这是不可能的,那么您可能应该寻找一个可以满足您网站需求的新网站托管服务商,而不是让您的网站适应您当前的网站托管服务商。
【解决方案2】:
您好,您需要编写自己的 HttpModule。
这是一个很好的例子 (it is from here):
看看那个网站,它会描述所有需要的步骤。
using System;
using System.Web;
public class DavModule : IHttpModule {
private HttpApplication context = null;
public void Dispose() {
context.BeginRequest -= new EventHandler(context_BeginRequest);
}
public void Init(HttpApplication context) {
this.context = context;
this.context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e) {
HttpApplication app = (HttpApplication) sender;
app.Response.ContentType = "text/plain";
if (app.Request.Path.EndsWith("Help"))
app.Server.Transfer("Help.aspx");
else {
app.Response.Write("Path: " + app.Request.Path);
app.Response.End();
}
}
}
【解决方案3】:
如果您刚开始(或者如果这样做是一种选择),那么问题就在于您(您的主机)是否在 IIS(6 或 7)上安装了 ASP.Net 4。
无扩展 url 是 ASP.Net 4 的一部分 - 这意味着您的 ASP.Net 站点(您希望无扩展 url 工作)必须在 ASP.net 4(不是 v2 .x)...
第...