0

I tried to URLRewrite module to redirect, rewrite and abort requests to site. But site shown error.

I wrote down IHttpModule which does similar, and calls HttpApplication.Context.Response.End(); in 'HttpApplication.BeginRequest'. This leads to direct jump into EndRequest event. Site does not expect this and throws InvalidOperationException in its EndRequest indicating that trying to clean some database code even without initialization. The same with URLRewrite.

I think this is because End() call skips initialization.

How to prevent this error to be shown to user? Kind of swallow it without ability to modify 3rd party site.

I experimenting with other HttpApplication events and do not want request to be handled, i.e. nothing written down to database as part of request. Not results here yet, what other options?

  • What version of ASP.NET and IIS are you dealing with? If you are attempting to create pretty URLs, such as those in ASP.NET MVC, you can take a look at the Routing mechanism available out of the box in ASP.NET. [See this](http://www.asp.net/web-forms/overview/routing), assuming you're on a WebForms project. – Mario J Vargas May 30 '14 at 13:26
  • I use ASP.NET Web Forms in IIS 7.5 and .NET 4.5. – user3688458 May 30 '14 at 14:34
  • Awesome. Assuming that the URL Rewrite you talked about is for simply doing pretty URLs, such as `~/Directory/Action/SomeValue` which you expect it to be `~/Directory/Page.aspx?action=SomeValue`, I highly encourage you to use Routes. See the link I posted above. Routes are native to ASP.NET, so they're technically not a URL rewriter. – Mario J Vargas May 30 '14 at 14:51

0 Answers0