js获取c#后台方法,变量及session

一,js调用后台方法和变量

前端javascript脚本

<script language="javascript" type="text/javascript">
//    var lpServerIP = "192.168.2.180";//硬盘录像机ip
//    var lPort = 8001;
//    var lpUserName = "admin";
//    var lpPassword = "12345";
//    var lChannelNum = 2;
   
    var lpServerIP = "<%=getIpServerIP()%>";//硬盘录像机ip
    var lPort = "<%=iPort %>";
    var lpUserName = "<%=getlpUserName()%>";
    var lpPassword = "<%=getlpPassword()%>";
    var lChannelNum = "<%=iChannelNum %>";
    var UserID
   
    function Play()
    {
     var i;
     var Netocx = document.getElementById("NetOCX");
     UserID = Netocx.Login(lpServerIP,lPort,lpUserName,lpPassword);
     i = Netocx.StartRealPlay(lChannelNum,0, 0); 
     if (i == 0)
     {
      alert("预览失败!"); 
     }
    }

    function Stop()
    {
     var Netocx = document.getElementById("NetOCX");
     Netocx.StopRealPlay();
      Netocx.Logout();
    }

    function FullScreen()
    {
     var Netocx = document.getElementById("NetOCX");
     Netocx.FullScreenCtrl();
    }

    function Play1()
    {
     var Netocx1 = document.getElementById("NetOCX1");
     UserID = Netocx1.Login("172.7.76.85",8000,"admin","12345");
     Netocx1.StartRealPlay(0 ,0, 0); 
    }

    function Stop1()
    {
     var Netocx1 = document.getElementById("NetOCX1");
     Netocx1.StopRealPlay();
      Netocx1.Logout();
    }

 

</script>

 

后台cs

public partial class _Default : System.Web.UI.Page
    {
        public int iPort;
        public int iChannelNum;
        string ipServerIP = "";
        string ipUserName = "";
        string ipPassword = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //获取参数
                if (Request.QueryString["ID"] != null && Request.QueryString["Flag"] != null)
                {
                    string id = Request.QueryString["ID"].ToString();
                    string flag = Request.QueryString["Flag"].ToString();
                    DataSet ds = this.getVideoUrl(Convert.ToInt32(flag),Convert.ToInt32(id));
                    //获取具体参数
                    string startTimeStr = ds.Tables[0].Rows[0]["StartTime"].ToString();
                    string endTimeStr = ds.Tables[0].Rows[0]["EndTime"].ToString();
                    //判断时间范围
                    DateTime startTime = Convert.ToDateTime(startTimeStr);
                    DateTime endTime = Convert.ToDateTime(endTimeStr);
                    DateTime dtNow = DateTime.Now.ToLocalTime();
                    if (dtNow > startTime && endTime > dtNow || dtNow == startTime || dtNow == endTime)
                    {
                        string ip = ds.Tables[0].Rows[0]["DvrIP"].ToString();
                        string userName = ds.Tables[0].Rows[0]["UserName"].ToString();
                        string pwd = ds.Tables[0].Rows[0]["Pwd"].ToString();
                        string ChanelNumber = ds.Tables[0].Rows[0]["ChanelNumber"].ToString();
                        string[] ipStr = ip.Split(':');

                        ipServerIP = ipStr[0];
                        iPort = Convert.ToInt32(ipStr[1]);
                        ipUserName = userName;
                        ipPassword = pwd;
                        iChannelNum = Convert.ToInt32(ChanelNumber);
                        //iChannelNum = 1;//用来测试
                    }
                    else
                    {
                        Response.Write("<script lauguage = javascript>window.alert('当前时间未能访问,谢谢!');window.location.href='error.htm';</script>");
                    }

                   
                }
                else
                {
                    Response.Redirect("error.htm");
                }
               
            }
        }

        /// <summary>
        /// 获取网站视频调用url
        /// </summary>
        /// <param name="flag">访问权限,2为家长</param>
        /// <param name="userID">访问用户ID</param>
        /// <returns>数据集</returns>
        protected DataSet getVideoUrl(int flag,int userID)
        {
            string cmd = "exec spGetVideoUrlByFlagID "+flag+","+userID;
            return Common.SqlHelper.ExecuteDataSet(cmd);
           
        }
       

        protected string getIpServerIP()
        {
            //string lpServerIP = "192.168.2.180";//硬盘录像机ip
            return ipServerIP;
        }       

        protected string getlpUserName()
        {
            //string lpUserName = "admin";//用户名
            return ipUserName;
        }

        protected string getlpPassword()
        {
            //string lpPassword = "12345";//密码
            return ipPassword;
        }

        public static bool IsWindowsVistaOrNewer
        {
            get { return (Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6); }
        }


    }

 

二,js获取session

<script language="javascript" type="text/javascript">

function getUrl()
{

    var id = '<%=Session["fbt.ParentID"] %>';
    var flag = "2";   
    var strUrl = "VideoTest/OsInfo.aspx?ID="+id+"&Flag="+flag;
    window.location.href = strUrl;
    //alert(strUrl); 

}

posted on 2010-04-14 11:07  peter_zhang  阅读(15830)  评论(0编辑  收藏  举报