如何在 ASP.NET 中对图像源 URL 进行哈希处理
How to hash image source url in ASP.NET
嗨,我想发送带有图像源哈希的网址。怎么能做到?
法典:
Image img_ = new Image();
img_.ImageUrl = "ShowImageInRuntime.aspx?FileName=C://Images//Image.jpg";
我不想在页面中看到我的本地路径。感谢您的帮助
您需要在发送之前对路径和 base 64 编码执行加密,并在处理程序中执行相反的操作。
另一种选择是维护映射 XML,其中 XML 将包含路径和相应的标识符。在应用程序中获取具有路径的节点,然后选择 id 并将其附加到 url。在处理程序中,执行相反的操作以获取路径。
更新:添加示例代码
以 GUID 作为 ID 和相应文件名的 XML 文件。 通过使用 GUID,人们无法轻易猜出随机 ID。
<?xml version="1.0" encoding="utf-8" ?>
<mappings>
<map id="485D9075B9CA4d8d9DBA1AD9CD09FC13" fileName="c:'images'image1.jpg"/>
<map id="475D4A22B1FA4eda8234007BD327D7B9" fileName="c:'images'image2.jpg"/>
<map id="77623BF3094440c49AC65CEF76D1B824" fileName="c:'images'image3.jpg"/>
</mappings>
使用 LINQ to XML
public class ImageMapper
{
private XDocument Document { get; set; }
public ImageMapManager()
{
Document = XDocument.Load("Map.xml");
}
public string GetFileNameFromId(string id)
{
var result = from node in Document.Descendants("map")
where node.Attribute("id").Value.Equals(id, StringComparison.InvariantCultureIgnoreCase)
select node.Attribute("fileName").Value;
return (result == null || result.Count() == 0) ? null : result.ElementAt(0);
}
public string GetIdFromFileName(string fileName)
{
var result = from node in Document.Descendants("map")
where node.Attribute("fileName").Value.Equals(fileName, StringComparison.InvariantCultureIgnoreCase)
select node.Attribute("id").Value;
return (result == null || result.Count() == 0) ? null : result.ElementAt(0);
}
}
相关文章:
- Steam Web API:I'我不知道该如何处理这个看起来像哈希的url来生成图像
- 通过传递图像的URL通过javascript读取/处理图像-类似于PHP中的file_get_contents
- 如何处理'#'在谷歌地图的url中
- URL内部的元标记和脚本处理
- API的快速路由-当您有子资源时的URL处理程序
- 处理HTML类型'电子邮件''url'使用JavaScript
- 有些人有任何关于如何使用Modified Java Script Value处理返回Json(url)的示例
- 信息-未处理的socket.io url
- 从onclick处理程序获取URL
- 使用jquery从URL中删除查询字符串(处理问题)
- 如何在使用HTML5 pushState更改浏览器URL时处理后退按钮
- 处理Ember.js默认路由之外的页面URL哈希参数
- 当jquery脚本处理时,URL会扩展
- 没有客户端 URL 处理的动态网站
- 处理 URL 中的空格
- 这是如何处理基于从 url 获取值的两个 ajax 请求吗?
- 处理 MEAN 堆栈中的批量 URL
- URL 中的 PHP 处理片段标识符
- Dojo要求从第三方URL处理JS 404错误
- Phonegap:自定义URL处理冻结