博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

将js文件编译成动态链接库(dll)文件

Posted on 2007-02-12 15:42  余墨  阅读(367)  评论(0)    收藏  举报
只是将jscript封装到dll中,运行后即可见到脚本代码,并不起到保护jscript的作用.
//添加引用
private void EmbedScriptCode()
{
 
// Add the script to declare the function
 string js = ReadResourceString("wf.ContextMenu.ContextMenu.js");

  
if (!Page.ClientScript.IsStartupScriptRegistered("ContextMenuHelper"))
  Page.ClientScript.RegisterStartupScript(
this.GetType(),"ContextMenuHelper", js);
}


private string ReadResourceString(string resourceName)
{
 Assembly dll 
= Assembly.GetExecutingAssembly();
 StreamReader reader;
 reader 
= new StreamReader(dll.GetManifestResourceStream(resourceName));
 
string js = reader.ReadToEnd();
 reader.Close();

 
return js;
}