index.aspx.cs 4.69 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;
        protected void Page_Load(object sender, EventArgs e)
        {
            urlParams = "XYZ";

            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();

                }
            }

            string c = "nm";
            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 : "");
             
                //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 : "");


            }
        }
    }
}