惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
H
Heimdal Security Blog
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Schneier on Security
G
GRAHAM CLULEY
U
Unit 42
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
C
CERT Recently Published Vulnerability Notes
Google DeepMind News
Google DeepMind News
罗磊的独立博客
Stack Overflow Blog
Stack Overflow Blog
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
Cyberwarzone
Cyberwarzone
T
The Exploit Database - CXSecurity.com
Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - 司徒正美
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
V
Visual Studio Blog
博客园 - Franky
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
Jina AI
Jina AI
P
Proofpoint News Feed
P
Proofpoint News Feed
有赞技术团队
有赞技术团队
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 聂微东
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
S
Security Affairs
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
小众软件
小众软件
N
News | PayPal Newsroom
Cloudbric
Cloudbric
AWS News Blog
AWS News Blog
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
NISL@THU
NISL@THU

博客园 - !LEO

采用WF实现审批备案的流程定义 Inside Microsoft Windows SharePoint Services 3.0 Saas安全性问题讨论 NHibernate事务中执行SQL Winform+WebService分层模型 Winform+WebService离线处理 使用BackgroundWorker控件进行异步处理 C#读取Word表格中的数据 在多个方法中共享database object的方式 Reporting Service 初体验 解决vs2005 安装项目不支持中文的问题 Mutex类解决进程线程互斥问题 javascript:URL编解码和父子窗口交互 VisualStudio2005应用CSS和JavaScrpt的问题 两款oralce开发工具 NBear 不错 今日测试总结 SSIS计算行号 一起学习SSIS
Javascript调用C#静态函数
!LEO · 2007-06-11 · via 博客园 - !LEO

Client Code

function WriteLog( assetID, billID, billState, bizType, logInfo, linkUrl, note )
{
    var tmp = new CSFunction();
    tmp.AsseblyName = "ZCGL_Com.dll";
    tmp.TypeName = "Genersoft.JTGL.ZCGL.ZCGL_Com.AssetLogMgr";
    tmp.FunctionName = "WriteLog";
    tmp.AddParameter( "string", assetID );
    tmp.AddParameter( "string", billID );
    tmp.AddParameter( "string", billState );
    tmp.AddParameter( "string", bizType );
    tmp.AddParameter( "string", logInfo );
    tmp.AddParameter( "string", linkUrl );
    tmp.AddParameter( "string", note );
    var rtn = tmp.Execute();
    tem = null;
    return rtn;
}

Javascript 核心调用类

function CSFunction()
{
    this.AsseblyName = "";
    this.TypeName = "";
    this.FunctionName = "";
    this._paramString = "";
    this._split0 = "#;#";
    this._split1 = "#:#";
    this.AddParameter = function( type, value )
    {
        var exps = type + this._split1 + value + this._split0;
        this._paramString += exps;
    }
    this.Execute = function()
    {
        if( this.AsseblyName == "" )
        {
            window.alert( "缺少程序集参数" );
            return false;
        }
        if( this.TypeName == "" )
        {
            window.alert( "缺少类名参数" );
            return false;
        }
        if( this.FunctionName == "" )
        {
            window.alert( "缺少方法名参数" );
            return false;
        }
        var param = "";
        param += "asmb" + this._split1 + this.AsseblyName + this._split0;
        param += "type" + this._split1 + this.TypeName + this._split0;
        param += "func" + this._split1 + this.FunctionName + this._split0;
        param += this._paramString;
        param = escape( param );
        var xhttp= new ActiveXObject("Microsoft.XMLHTTP");
        try
        {
            xhttp.open("GET", "../../Public_Web/ExecCSFunction.aspx?param="+param, false);
            xhttp.send();
            var vsRetval = xhttp.responseText;       
            xhttp = null;
            if( vsRetval.substring( 0, 2 ) == "/1" )    { window.alert( vsRetval.substring( 2 ) ); return false; }
            return vsRetval;
        }
        catch(error)
        {
            window.alert( "CSFunction处理失败:" + error.description );
            return false;
        }   
    }
}

C#后台程序

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Reflection;
using System.Text.RegularExpressions;
using Genersoft.JTGL.Public_Com;

namespace Genersoft.JTGL.Public_Web
{
    /// <summary>
    /// Summary description for ExecCSFunction.
    /// </summary>
    public class ExecCSFunction : System.Web.UI.Page
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            #region clear cache

            Response.Buffer=true;
            Response.ExpiresAbsolute=System.DateTime.Now.AddSeconds(-1);
            Response.Expires=-1;
            Response.CacheControl="no-cache";

            #endregion

            string dllPath = Request.PhysicalApplicationPath + @"bin\";
            string AssemblyName = "", TypeName = "", FunctionName = "";
            ArrayList ReceiveParams = new ArrayList();
            object[] SendParams = new object[]{};

            Assembly assmebly;
            Type type;
            object rtnValue = new object();

            try
            {
                //接收参数
                string tempParam = Request.QueryString["param"];
                if( CommonFunction.IsEmptyOrNull( tempParam ) )
                {
                    throw new Exception( "缺少param参数" );
                }

                //解析参数
                ParseQueryString( tempParam, ref AssemblyName, ref TypeName, ref FunctionName, ref SendParams );

                //加载程序集           
                assmebly = Assembly.LoadFrom( dllPath + AssemblyName );   
                //调用方法
                type = assmebly.GetType( TypeName );
                rtnValue = type.InvokeMember( FunctionName,  BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static, null, null, SendParams);
            }
            catch( Exception ex )
            {
                Response.Write( @"/1ExecCSFucntion处理失败:" + ex.Message );
                Response.End();
            }

            if( rtnValue == null )    rtnValue = @"/0";//表示没有返回值或返回值为null
            Response.Write( rtnValue );
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {   
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion

        private void ParseQueryString( string queryString, ref string asmbName, ref string typeName, ref string funcName, ref object[] objectParam  )
        {
            ArrayList param = new ArrayList();
            string split0 = "#;#", split1 = "#:#";
            typeName = "";
            funcName = "";
            asmbName = "";

            string[] splitParam = Regex.Split( queryString, split0 );
            for( int i=0; i<splitParam.Length; i++ )
            {
                if( splitParam[i] == "" )    continue;
                string[] exps = Regex.Split( splitParam[i], split1 );
                if( exps[0] == "type" )
                {
                    typeName = exps[1];
                }
                else if( exps[0] == "func" )
                {
                    funcName = exps[1];
                }
                else if( exps[0] == "asmb" )
                {
                    asmbName = exps[1];
                }
                else
                {
                    switch( exps[0] )
                    {
                        case "string":
                            param.Add( exps[1] );
                            break;
                        case "int":
                            param.Add( Convert.ToInt32( exps[1] ) );
                            break;
                        case "decimal":
                            param.Add( Convert.ToDecimal( exps[1] ) );
                            break;
                    }
                }
            }

            objectParam = new object[ param.Count ];
            for( int i=0; i<param.Count; i++ )
            {
                objectParam[i] = param[i];
            }
        }
    }
}