【发布时间】:2011-11-28 04:58:13
【问题描述】:
我有一个 ASP.NET 4 HttpModule(参见下面的代码)。当 url 路径以“/1.0”开头时,我希望 Cassini/IIS 转到 MyService.svc。但是,我不想向用户显示“MyService.svc”(即浏览器中的 url 没有更新)。我希望用户看到“www.something.com/1.0”。
我很确定 RewriteUrl 不应该更改浏览器的 url,但在我的情况下它会。知道为什么吗?
public void Init(HttpApplication context)
{
context.BeginRequest +=
delegate
{
HttpContext ctx = HttpContext.Current;
const string BasePath = "~/1.0";
if (path.StartsWith(BasePath, StringComparison.OrdinalIgnoreCase))
{
ctx.RewritePath("~/MyService.svc", "this/is/a/path", string.Empty, false);
}
};
}
附:由于 URL 中的句点/点,我无法使用 ASP.NET 路由(请参阅ASP.NET MVC Route IDs with a period)。
【问题讨论】:
标签: c# asp.net url-rewriting httpmodule cassini