您好,登錄后才能下訂單哦!
這篇文章主要介紹了如何隱藏ASP中的MediaPlayer控件播放文件地址,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
在播放視頻時(shí),直接查看頁面源文件可看到視頻文件地址,MediaPlayer控件播放器將在頁面上加上如下初始化語句:
MediaPlayer控件初始化可查看到源文件地址
Sys.Application.add_init(function() { $create(Sys.UI.Silverlight.MediaPlayer, {"autoPlay":true,"mediaSource":"http://211.142.31.235/Nas1/VOD/CP0001/490Kbps/D/DI/DIA/DiaoZhongYuan1/DiaoZhongYuan1.wmv","scaleMode":2,"source":"UserControl/playerTheme/player.xaml","volume":1}, null, null, $get("myUserMediaPlayer_player_parent")); });
解決方案是先建立一個(gè)字符串加密解密服務(wù)
加密、解密工具類
1/**//// <summary> 2 /// 對(duì)字符串進(jìn)行、加解密的工具類 3 /// </summary> 4 public class DESEncryptor 5 { 6 靜態(tài)公共方法#region 靜態(tài)公共方法 7 /**//// <summary> 8 /// 對(duì)字符串進(jìn)行加密 9 /// </summary> 10 /// <param name="strSource">源字符串</param> 11 /// <returns>加密后的字符串</returns> 12 public static string ExecEncrypt(string strSource) 13 { 14 DESEncryptor desEncryptor = new DESEncryptor() ; 15 desEncryptor.InputString = strSource ; 16 desEncryptor.DesEncrypt() ; 17 return desEncryptor.OutString ; 18 } 19 /**//// <summary> 20 /// 對(duì)已經(jīng)加密的字符串進(jìn)行解密 21 /// </summary> 22 /// <param name="strSource">已經(jīng)加密的字符串</param> 23 /// <returns>還原后的字符串</returns> 24 public static string ExecDeEncrypt(string strSource) 25 { 26 DESEncryptor desEncryptor = new DESEncryptor() ; 27 desEncryptor.InputString = strSource ; 28 desEncryptor.DesDecrypt() ; 29 return desEncryptor.OutString ; 30 } 31 #endregion 32 33 私有成員#region 私有成員 34 /**//// <summary> 35 /// 輸入字符串 36 /// </summary> 37 private string inputString=null; 38 /**//// <summary> 39 /// 輸出字符串 40 /// </summary> 41 private string outString=null; 42 /**//// <summary> 43 /// 輸入文件路徑 44 /// </summary> 45 private string inputFilePath=null; 46 /**//// <summary> 47 /// 輸出文件路徑 48 /// </summary> 49 private string outFilePath=null; 50 /**//// <summary> 51 /// 加密密鑰 52 /// </summary> 53 private string encryptKey="fanmenglife"; 54 /**//// <summary> 55 /// 解密密鑰 56 /// </summary> 57 private string decryptKey = "fanmenglife"; 58 /**//// <summary> 59 /// 提示信息 60 /// </summary> 61 private string noteMessage=null; 62 #endregion 63 64 公共屬性#region 公共屬性 65 /**//// <summary> 66 /// 輸入字符串 67 /// </summary> 68 public string InputString 69 { 70 get{return inputString;} 71 set{inputString=value;} 72 } 73 /**//// <summary> 74 /// 輸出字符串 75 /// </summary> 76 public string OutString 77 { 78 get{return outString;} 79 set{outString=value;} 80 } 81 /**//// <summary> 82 /// 輸入文件路徑 83 /// </summary> 84 public string InputFilePath 85 { 86 get{return inputFilePath;} 87 set{inputFilePath=value;} 88 } 89 /**//// <summary> 90 /// 輸出文件路徑 91 /// </summary> 92 public string OutFilePath 93 { 94 get{return outFilePath;} 95 set{outFilePath=value;} 96 } 97 /**//// <summary> 98 /// 加密密鑰 99 /// </summary> 100 public string EncryptKey 101 { 102 get{return encryptKey;} 103 set{encryptKey=value;} 104 } 105 /**//// <summary> 106 /// 解密密鑰 107 /// </summary> 108 public string DecryptKey 109 { 110 get{return decryptKey;} 111 set{decryptKey=value;} 112 } 113 /**//// <summary> 114 /// 錯(cuò)誤信息 115 /// </summary> 116 public string NoteMessage 117 { 118 get{return noteMessage;} 119 set{noteMessage=value;} 120 } 121 #endregion 122 123 構(gòu)造函數(shù)#region 構(gòu)造函數(shù) 124 /**//// <summary> 125 /// 構(gòu)造函數(shù) 126 /// </summary> 127 public DESEncryptor() 128 { 129 // 130 // TODO: 在此處添加構(gòu)造函數(shù)邏輯 131 // 132 } 133 #endregion 134 135 DES加密字符串#region DES加密字符串 136 /**//// <summary> 137 /// 加密字符串 138 /// 注意:密鑰必須為8位 139 /// </summary> 140 public void DesEncrypt() 141 { 142 byte[] byKey=null; 143 byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; 144 try 145 { 146 byKey = System.Text.Encoding.UTF8.GetBytes(this.encryptKey.Substring(0,8)); 147 DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 148 byte[] inputByteArray = Encoding.UTF8.GetBytes(this.inputString); 149 MemoryStream ms = new MemoryStream(); 150 CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ; 151 cs.Write(inputByteArray, 0, inputByteArray.Length); 152 cs.FlushFinalBlock(); 153 this.outString=Convert.ToBase64String(ms.ToArray()); 154 } 155 catch(System.Exception error) 156 { 157 this.noteMessage=error.Message; 158 } 159 } 160 #endregion 161 162 DES解密字符串#region DES解密字符串 163 /**//// <summary> 164 /// 解密字符串 165 /// </summary> 166 public void DesDecrypt() 167 { 168 byte[] byKey = null; 169 byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF}; 170 byte[] inputByteArray = new Byte[this.inputString.Length]; 171 try 172 { 173 byKey = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0,8)); 174 DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 175 inputByteArray = Convert.FromBase64String(this.inputString); 176 MemoryStream ms = new MemoryStream(); 177 CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write); 178 cs.Write(inputByteArray, 0, inputByteArray.Length); 179 cs.FlushFinalBlock(); 180 System.Text.Encoding encoding = new System.Text.UTF8Encoding(); 181 this.outString=encoding.GetString(ms.ToArray()); 182 } 183 catch(System.Exception error) 184 { 185 this.noteMessage=error.Message; 186 } 187 } 188 #endregion 189}
加密、解密WebService,調(diào)用工具內(nèi)加密、解密方法:
1/**//// <summary> 2 /// Summary description for Service1 3 /// </summary> 4 [WebService(Namespace = "http://tempuri.org/")] 5 [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 6 [System.ComponentModel.ToolboxItem(false)] 7 // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 8 // [System.Web.Script.Services.ScriptService] 9 public class Service1 : System.Web.Services.WebService 10 { 11 /**//// <summary> 12 /// 加密 13 /// </summary> 14 /// <param name="url">地址</param> 15 /// <returns></returns> 16 [WebMethod] 17 public string Encrypt(string url) 18 { 19 return DESEncryptor.ExecEncrypt(url); 20 } 21 22 /**//// <summary> 23 /// 解密 24 /// </summary> 25 /// <param name="url">地址</param> 26 /// <returns></returns> 27 [WebMethod] 28 public string DeEncrypt(string url) 29 { 30 return DESEncryptor.ExecDeEncrypt(url); 31 } 32 }
在MediaPlayer控件播放頁面加載時(shí),先調(diào)用WebService內(nèi)加密方法對(duì)播放地址進(jìn)行加密,然后注冊JavaScript腳本調(diào)用視頻文件播放方法:
播放頁面加載
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //對(duì)播放地址進(jìn)行加密 string encryptUrl = local.Encrypt(playUrl); //注冊腳本,調(diào)用javascript播放方法 Page.ClientScript.RegisterStartupScript(this.GetType(), "", " setTimeout(\"onPlay('" + encryptUrl + "')\",1000)", true); } }
JavaScript調(diào)用WebService通過微軟提供的WebService.htc實(shí)現(xiàn),ASP.NET中使用WebService.htc需要在HTML代碼中添加如下代碼:
<div id="serviceDiv" style="behavior: url(WebService.htc)"></div>
注意:該div必需在forms之外
Javascript代碼:
1 function getUrl(str) { 2 //***個(gè)參數(shù)是webservice的url,后面是名稱 3 serviceDiv.useService("http://localhost:88/Service1.asmx?WSDL", "news"); 4 //設(shè)置一個(gè)回調(diào)函數(shù),service返回結(jié)果的時(shí)候回調(diào);***個(gè)參數(shù)是回調(diào)函數(shù)的名稱,后面的是webservice的參數(shù) 5 intCallID = serviceDiv.news.callService(url_result, "DeEncrypt", str); //這里有兩個(gè)參數(shù).. 6 } 7 8 function url_result(result)//回調(diào)函數(shù) 9 { 10 var media_player = $find('myUserMediaPlayer_player'); 11 media_player.set_mediaSource(result.value); 12 media_player.set_autoPlay(true); 13 } 14 15 function onPlay(str) { 16 getUrl(str); 17 }
有幾點(diǎn)需說明:
1. 為什么在Page_Load事件里注冊腳本不直接調(diào)用Javascript內(nèi)播放方法,因?yàn)轫撁嫘柰耆虞d后,WebService.htc才會(huì)被初始化,所以我用setTimeout方法延遲一段時(shí)間再調(diào)用播放方法。
2. 大家在使用WebService回調(diào)函數(shù)時(shí)記得判斷返回結(jié)果是否成功。
通過以上方法,在頁面上查看源文件便無法查看到播放文件地址了,MediaPlayer初始化語句更新為如下:
更改后MediaPlayer控件初始化
Sys.Application.add_init(function() { $create(Sys.UI.Silverlight.MediaPlayer, {"autoPlay":true,"scaleMode":1,"source":"../UserControl/playerTheme/VIPPlayer.xaml","volume":1}, null, null, $get("ump_player_parent")); });
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“如何隱藏ASP中的MediaPlayer控件播放文件地址”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。