More in this section
Forums / Developing with Sitefinity / how to make a website to be pwd protected?

how to make a website to be pwd protected?

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. Inna
    Inna avatar
    97 posts
    Registered:
    08 Jun 2012
    03 May 2012
    Link to this post
    is it possible to do with sitefinity? has anybody done it? if not, where you successful with your own code? i can't make mine to work. here is the code in the global file:

    <%@ Application Language="C#" %>

    <script runat="server">

        public override string GetVaryByCustomString(HttpContext context, string custom)
        {
            if (custom.Equals("cms"))
            {
                return String.Concat(context.Request.Url.Host, context.Request.RawUrl, context.Request.Browser.Type).ToLower();
            }
            return base.GetVaryByCustomString(context, custom);    
        }

        void Application_Start(object sender, EventArgs e)
        {}
        
        void Application_End(object sender, EventArgs e)
        {}
            
        void Application_Error(object sender, EventArgs e)
        {}
        
        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
            string sLoginNeeded;
            String sArg = Request.RawUrl.ToString();

            if (sArg.ToLower().Contains("sitefinity"))
            {
                sLoginNeeded = "False";
                Session["NeedsLogin"] = sLoginNeeded;
                return;
            }

            sLoginNeeded = "True";

            try
            {
                string addr;
                addr = Request.ServerVariables["REMOTE_ADDR"];
                if (addr != "96.234.156.18" & !(addr.StartsWith("10.19")))
                {
                    Session["NeedsLogin"] = "True";
                    sLoginNeeded = "True";
                }

                else
                {
                    sLoginNeeded = "False";
                }
            }
            catch (Exception ex)
            {
                
            }
            Session["NeedsLogin"] = sLoginNeeded;
        }

        void Session_End(object sender, EventArgs e)
        {
            
        }

        protected void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            var context = System.Web.HttpContext.Current.Session;
            if (context == null) return;
            
            string sLoginNeeded;

            try
            {
                String sArg = Request.Url.ToString();
                
                if (sArg.ToLower().EndsWith("login.aspx"))
                {
                    return;
                }
                else
                {
                    if (context["NeedsLogin"].ToString() == null)
                        sLoginNeeded = "True";

                    else
                        sLoginNeeded = context["NeedsLogin"].ToString();

                    if (sLoginNeeded == "True")
                        Response.Redirect("login.aspx", false);
                }

            }
            catch (Exception ex)
            {
            }

        }
           
    </script>

    And here is the code in the login1.aspx.cs file:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    public partial class mylogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Session["RedirectLogin"] = "NotRedirected";
            //Response.Write(Session["OriginalURL"]);
        }


        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //try
            //{
                if (txtUserID.Text.Trim().ToLower() == "employee")
                {
                    if (txtPassword.Text.Trim().ToLower() == "cityhall")
                    {
                        Session["NeedsLogin"] = "False";
                        if (Session["OriginalURL"] != null)
                        {
                            if  ( ! Session["OriginalURL"].ToString().ToLower().EndsWith("login.aspx") )
                                ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='" + Session["OriginalURL"] + "'", true);
                            else
                                ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='Default.aspx'", true);
                        }
                        else
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "scriptid", "window.parent.location.href='Default.aspx'", true);
                        }
                    }
                }
            //}
            //catch (Exception ex)
            //{
            //}
        }
    }

    please help.
1 posts, 0 answered