Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 132003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:11:39+00:00 2026-05-11T06:11:39+00:00

I need to write a custom UrlRewriter using a HttpModule, in the moment of

  • 0

I need to write a custom ‘UrlRewriter’ using a HttpModule, in the moment of ‘rewriting’ I need access to the Session and has followed the advice from another SO thread:

Can I access session state from an HTTPModule?

Everything works, except the RewritePath/Redirect part. I don’t get any exceptions, but the browser takes forever to load. Is this really the best way to build a urlrewriter like this?

using System; using System.Web; using System.Web.SessionState; using System.Diagnostics;  namespace MyCompany.Campaigns {      public class CampaignRewriteModule : IHttpModule     {         public void Init(HttpApplication application)         {             application.PostAcquireRequestState += new EventHandler(Application_PostAcquireRequestState);             application.PostMapRequestHandler += new EventHandler(Application_PostMapRequestHandler);         }          void Application_PostMapRequestHandler(object source, EventArgs e)         {             HttpApplication app = (HttpApplication)source;              if (app.Context.Handler is IReadOnlySessionState || app.Context.Handler is IRequiresSessionState)             {                 return;             }              app.Context.Handler = new MyHttpHandler(app.Context.Handler);         }          void Application_PostAcquireRequestState(object source, EventArgs e)         {             HttpApplication app = (HttpApplication)source;              MyHttpHandler resourceHttpHandler = HttpContext.Current.Handler as MyHttpHandler;              if (resourceHttpHandler != null)             {                 HttpContext.Current.Handler = resourceHttpHandler.OriginalHandler;             }              Debug.Assert(app.Session != null);               string path = HttpUtils.Path();              if (!CampaignCodeMethods.IsValidCampaignCode(path)) return;              string domain = HttpUtils.Domain();              CampaignCode code = CampaignManager.RegisterCode(path, domain.Equals(Config.Instance.Domain.ToLower()) ? null : domain);              if (code != null)             {                //app.Context.RewritePath(code.CampaignCodePath.Path, false);                app.Context.Response.Redirect(code.CampaignCodePath.Path, true);             }           }          public void Dispose() { }          public class MyHttpHandler : IHttpHandler, IRequiresSessionState         {             internal readonly IHttpHandler OriginalHandler;              public MyHttpHandler(IHttpHandler originalHandler)             {                 OriginalHandler = originalHandler;             }              public void ProcessRequest(HttpContext context)             {                 throw new InvalidOperationException('MyHttpHandler cannot process requests.');             }              public bool IsReusable             {                 get { return false; }             }         }      }  } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T06:11:40+00:00Added an answer on May 11, 2026 at 6:11 am

    I think I know what it is. Your module is executed on ALL requests and assigns a handler that throws an error unless there is a valid campaign code (where a rewrite/redirect occurs).

    But because this is not just for your ‘handler campaign code’ url it is causing an error to be thrown, which is causing you to be redirected to your error page, which is being caught by the module, which is assigning the handler, which is throwing an error, which is redirecting… I think you get where I’m going 😉

    Otherwise I’d try a few things:

    • Setup Fiddler and check for an infinite redirect loop
    • Put a breakpoint on app.Context.Response.Redirect – make sure your not in an infinite loop
    • Put a breakpoint on MyHttpHandler.ProcessRequest – make sure it’s not being called and the exception swallowed
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write custom ord and chr functions. I'm writing a little program
Is there any need to use a custom buffer to either read or write
I need to write a script in Matlab, which will read some data from
I need to write a C++ code coverage program that takes in another C++
I need to write to a text file using JavaScript. I have a machine
I need to write a custom web-scraper to mine some data. ?I know how
I am using Lucene.Net 2.9.2 and I reckon I will need to write a
I have an IList attribute in my Model. I need to write a custom
I need to write a custom WPF control that should look like a ComboBox
Do I need to make a Custom Membership Provider or is there another way?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.