locked
HTTPS for single page (using Global.asax Application_BeginRequest method) RRS feed

  • Question

  • User718865757 posted

    Hi,

    I want HTTPS for only login.aspx , and for all other pages normal http.

    void Application_BeginRequest(object sender, EventArgs e)
            {
                var absolutepath = Request.Url.AbsolutePath;
                var ext = System.IO.Path.GetExtension(Request.Url.AbsolutePath);
    
                if (absolutepath.Contains("login.aspx") || absolutepath.ToLower().Contains("webresource.axd") || ext.ToLower() == ".png" || ext.ToLower() == ".css" || ext.ToLower() == ".js" || ext.ToLower() == ".jpg" || ext.ToLower() == ".gif")
                {
                    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http:"))
                    {
                        Response.Redirect(HttpContext.Current.Request.Url.ToString().ToLower().Replace("http:", "https:"));
                    }
                }
                else
                {
                    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("https:"))
                    {
                        Response.Redirect(HttpContext.Current.Request.Url.ToString().ToLower().Replace("https:", "http:"));
                    }
                }
    
            }

    This is my method.

    The problem in this is ,

    when login.aspx is loading in background all jpg,png,css,js,axd files are loading. if none of them converted into HTTPS certificate is getting error. So i included them in if condition along with login.aspx

    But When i want to convert https to http then also its converting into https only instead of http. Because i put or condition in first IF condition.

    The help i required here is. I want to convert all the background files to https only if the page is login.aspx , otherwise http.

    Sorry for my english.

    Thank you.

    Monday, July 7, 2014 10:54 AM

All replies