【发布时间】:2009-05-12 15:41:17
【问题描述】:
当我尝试在 ASP.NET 中重写 URL 时,我发现用户浏览器上的 URL 发生了变化。我正在使用 WCF REST 服务,并且我想更改您访问 URL 的方式。请参阅下面的代码示例。
我有一个正在拦截请求的 HttpModule。
public class FormatModule : IHttpModule
{
#region IHttpModule Members
public void Dispose()
{
throw new NotImplementedException();
}
public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(application_BeginRequest);
}
void application_BeginRequest(object sender, EventArgs e)
{
HttpContext context = HttpContext.Current;
if (context.Request.RawUrl.Contains(".pox"))
context.RewritePath("~/Lab1Service.svc?format=pox", false);
else if (context.Request.RawUrl.Contains(".json"))
context.RewritePath("~/Lab1Service.svc?format=json", false);
}
#endregion
}
当用户在浏览器中访问 URL 时会出现问题。
http://localhost/Lab1Service.svc.pox,而是将浏览器中的 URL 更改为 http://localhost/Lab1Service.svc?format=pox。
【问题讨论】: