index.aspx.cs 5.66 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ADAM.AIA
{
    public partial class index : System.Web.UI.Page
    {
        public string strIPAddress = "";
        public bool bValidIP = false;
        public string strAccountNumber = "";
        public string strEdition = "";
        public string strUrlReferer = "";
        public string strSiteReferer = "";
        public string urlParams = "";
        public string test = "";
        public bool isCalsCredantial = false;

        public string version = "1.0." + DateTime.Now.Hour.ToString();//refresh script and css by adding version every hour

        protected void Page_Load(object sender, EventArgs e)
        {
           

            if (Request.HttpMethod == "POST")
            {
                if (Request.Form["calsCredantial"] != null && Request.Form["calsCredantial"].ToString() == "yes")
                {
                    isCalsCredantial = true;
                 
                    urlParams = "calsCredantial=" + Request.Form["calsCredantial"].ToString() + "&username=" + Request.Form["calsUsername"].ToString() + "&password=" + Request.Form["calsPassword"].ToString();
                    //calsCredantialusername&password
                   // urlParams = Request.Form["calsCredantial"].ToString() + "&username=" + Request.Form["calsUsername"].ToString() + "&password=" + Request.Form["calsPassword"].ToString();

                }
            }

            if (Request.QueryString["mtype"] != null)
            {
                //birendra
                //open default CA module by query string
                isCalsCredantial = true;
               
                string[] allQueryData = new string[Request.QueryString.AllKeys.Length];

                for(int i=0;i< Request.QueryString.AllKeys.Length; i++)
                {
                    allQueryData[i] = Request.QueryString.AllKeys[i] + "=" + Request.QueryString[Request.QueryString.AllKeys[i]].ToString();
                }
                urlParams = string.Join("&", allQueryData);

                //urlParams = "mtype=" + Request.QueryString[allQueryData[].ToString() + "&id=" + Request.QueryString["id"].ToString() + "&username=" + Request.QueryString["username"].ToString() + "&password=" + Request.QueryString["password"].ToString();
            }
            else if (Request.QueryString["account"] != null)
            {
                // http://stackoverflow.com/questions/9032005/request-servervariableshttp-referer-is-not-working-in-ie
                // http://stackoverflow.com/questions/5643773/http-referrer-not-always-being-passed?rq=1
                //
                strSiteReferer = Request.ServerVariables["HTTP_REFERER"];
                strAccountNumber = Request.QueryString["account"];
                strEdition = Request.QueryString["edition"];
                string remoteIPAddress = Request.ServerVariables["REMOTE_ADDR"];
                string strHttpReferer = null;
                int intSiteId = 0;




                if (Request.Form["referer"] != null)
                {
                    strUrlReferer = Request.Form["referer"];
                }
                else if (Request.QueryString["referer"] == null)
                {
                    strUrlReferer = Request.ServerVariables["HTTP_REFERER"];
                }
                else if (Request.Params["referer"] != null)
                {
                    strUrlReferer = Request.Params["referer"];
                }
                else
                {

                    strUrlReferer = Request.QueryString["referer"];
                }


                if (strUrlReferer != "" && strUrlReferer != null)
                {
                    strHttpReferer = strUrlReferer.ToLower().Replace("http://", "").Replace("https://", "").Replace("www.", "").ToString().Split('/')[0].ToString();

                    if (strHttpReferer.IndexOf(":") != -1)
                    {
                        char[] delimiters = new char[] { ':' };
                        string[] parts = strHttpReferer.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                        strHttpReferer = parts[0];
                    }
                }

                try
                {

                    if (strHttpReferer != "" && strHttpReferer != null)
                        strIPAddress = strHttpReferer;
                    if (strIPAddress == "" || strIPAddress == null)
                        strIPAddress = remoteIPAddress;


                  //  intSiteId = LicenseHelper.GetInstance().ValidateLicenseSiteIP(strIPAddress, remoteIPAddress, strAccountNumber, Convert.ToByte(strEdition));

                }
                catch (Exception objEx)
                {

                }
                //urlParams = "?siteIP=" + strIPAddress + "&status=" + intSiteId + "&accountNumber=" + strAccountNumber + "&edition=" + strEdition + "&urlReferer=" + (strSiteReferer != "" && strSiteReferer != null ? strSiteReferer : "");
                urlParams = "siteIP=" + strIPAddress + "&accountNumber=" + strAccountNumber + "&edition=" + strEdition + "&urlReferer=" + (strSiteReferer != "" && strSiteReferer != null ? strSiteReferer : "") + "&remoteIPAddress=" + remoteIPAddress;
             
                //For the ease of splitting desgined urlParms in the pattern of 
                //urlParams = siteIP&accountNumber&remoteIPAddress&edition&urlReferer; without mentioning the variableName
              //  urlParams = strIPAddress + "&" + remoteIPAddress+"&"+  strAccountNumber + "&" + strEdition + "&" + (strSiteReferer != "" && strSiteReferer != null ? strSiteReferer : "");


            }
        }
    }
}