When I try to rewrite the URL in ASP.NET, I find that the URL changes in the user's browser. I am using WCF REST services and I want to change the way URLs are accessed. See the sample code below.
I have an HttpModule that intercepts requests.
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
}
The problem occurs when users visit the URL in their browser.
http: //localhost/Lab1Service.svc.pox , instead the URL changes in the browser to http: //localhost/Lab1Service.svc? format = pox .
source
share