ImageController
string path=
string imgName =
long ticks=DateTime
//使用當前時間刻度作為待加密對象
string encryptKey = ticks
//使用自定義對稱算法加密
byte[] data = SymmetricEncryptionUtility
(
encryptKey
ShareData
);
//使加密後的數據轉換成base
string encryptedImgName = Convert
string encryptedEncoding = HttpUtility
(
encryptedImgName
);
//將加密後的密文存放在共享數據中
ShareData
ViewData[
(
ImageHandler
public void ProcessRequest(HttpContext context)
{
HttpResponse response = context
HttpRequest request = context
string imgKey = request
byte[] data = Convert
string decryptedKey = SymmetricEncryptionUtility
(
data
ShareData
);
//如果沒有圖片密鑰就返回
if (imgKey == null) return;
string imagePath = null;
//檢查請求是否來自外站
if (request
{
if (String
request
request
true
CultureInfo
{
if (!ShareData
return;
imagePath = request
if (!File
{
response
return;
}
}
}
else//不是本站
{
long ticks;
if (long
{
TimeSpan ts = new TimeSpan
(
DateTime
);
//如果大於一個月
if (ts
{
//輸出鏈接過期
return;
}
}
}
//移除共享數據中key
ShareData
response
+ Path
response
}
因為是自定義Handler注意在config中注冊handler節點
nfig
<httpHandlers> <add verb=
<add verb=
</httpHandlers>
以上的解決方案只代表個人
From:http://tw.wingwit.com/Article/program/net/201311/11636.html