locked
Session with URL ReWrite RRS feed

  • Question

  • User953143284 posted

    Hi,

    I've been trying to fix a problem that I've but I honestly donno if it can be donne.

    I want to use URL ReWrite with a session value.

    I tryed with Global.asax but on Application_BeginRequest session doesn't exists yet. Also on Application_AcquireRequestState but I think it's too late for the ReWritePath. This is what I've:

    void Application_AcquireRequestState(object sender, EventArgs e)
        {
            // && HttpContext.Current.Session["key"] != null
            if (System.Web.HttpContext.Current.Session != null )
            {
                string fullOrigionalpath = Request.CurrentExecutionFilePath.ToLower();
                HttpContext.Current.Session.Add("passei", fullOrigionalpath);   // Works ok!
                if (fullOrigionalpath.Contains("aspx"))
                {
                    if (fullOrigionalpath.CompareTo("/default.aspx") == 0)
                    {
                        HttpContext.Current.RewritePath("/Autenticacao/Login.aspx");
                    }
                }
            }
    }

    Any advice?

    Tuesday, April 21, 2015 9:50 AM

All replies

  • User2008642861 posted

    Hi AGodinho,

    Thank you for your post. I think you could try below code.

    HttpContext.RewritePath("/Autenticacao/Login.aspx");
    

    About how to use HttpContext.RewritePath Method (String), please check the below link.

    https://msdn.microsoft.com/en-us/library/sa5wkk6d.aspx

    Hope this could be helpful to you.

    Best regards,

    Archer

    Wednesday, April 22, 2015 1:47 AM
  • User953143284 posted

    I had tryed this:

    Context.RewritePath("/Autenticacao/Login.aspx");

    But it gives me a 404 ERROR, the ReWrite is completely ignored...

    Like I thought, if I use this on Application_BeginRequest works perfectly:

            string fullOrigionalpath = Request.Url.ToString();
    
            if (fullOrigionalpath.Contains("/Login.aspx"))
            {
                Context.RewritePath("/Autenticacao/Login.aspx");
            }

    Wednesday, April 22, 2015 3:46 AM
  • User2008642861 posted

    Hi AGodinho,

    As I know, Session is not accessed at Application_BeginRequest.

    http://stackoverflow.com/questions/16047631/url-rewriting-in-global-asax-iis7

    http://www.codeproject.com/Questions/438086/URL-Rewriting-does-not-work-on-production-server

    Above are two similar case abour rewrite url at Application_AcquireRequestState. It seems that we may not rewrite url at Application_AcquireRequestState.

    So, I suggest that you could rewrite at Application_BeginRequest.

    Best regards,

    Archer

    Wednesday, April 22, 2015 4:49 AM