Note that there are some explanatory texts on larger screens.

plurals
  1. POUrlRewriter+HttpModule+Session problem
    primarykey
    data
    text
    <p>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:</p> <p><a href="https://stackoverflow.com/questions/276355/can-i-access-session-state-from-an-httpmodule">Can I access session state from an HTTPModule?</a></p> <p>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?</p> <pre><code>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; } } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload