c# - 尝试获取服务器端图像进行处理时出现“访问路径被拒绝”错误
问题描述
我正在研究一个解决方案,在该解决方案中,我需要将上传的图像转换为 base 64 字符串,我的代码在 localhost 上运行良好,但是当我将它上传到服务器时,它让我可以访问路径'C:\ Inetpub\vhosts\xyz.com\xyz.com\Resources\Address\1002055.jpg' 被拒绝。
这是我的代码片段,
strFileName = fuPhoto.FileName;
strFileExtension = Path.GetExtension(fuPhoto.FileName);
if (strFileExtension.ToLower() == ".jpg" || strFileExtension.ToLower() == ".jpeg" || strFileExtension.ToLower() == ".png")
{
CSPProfileFile = Functions.GetFileName(hdnCSPCode.Value + strFileExtension);
fuPhoto.SaveAs(Server.MapPath(Path.Combine("~/Resources/Profile/", CSPProfileFile)));
base64_photo = ConvertToBase64Image(Server.MapPath("~/Resources/Profile/"+CSPProfileFile));
}
我使用了一个简单的base64字符串转换方法
internal static string ConvertToBase64Image(string file)
{
return Convert.ToBase64String(File.ReadAllBytes(file));
}
此代码在 localhost 环境中运行良好,但当我将其发布到服务器时出现错误 - 拒绝访问路径'C:\Inetpub\vhosts\xyz.com\xyz.com\Resources\Address\1002055.jpg'。
以前相同的代码在服务器上也可以正常工作,我是不是写错了..
解决方案
推荐阅读
- python - Matplotlib 3d scatter _facecolors3d 不工作
- gitlab - Gitlab : Peer 的证书颁发者已被用户标记为不信任
- python - 在 PyCharm 中看不到 pyc 文件
- c# - Web API 生成空白 PDF
- python - 如何扩展数据框中的列?
- java - Spring JPA 数据,具有相同功能的多个方法
- mysql - MySQL 从具有列名的所有表中选择
- c# - 在 .NET Core 3.1 中的 Windows 服务中调用工作单元可靠的业务服务
- scala - 无法使用 Spark Scala 写入带有标头的 CSV
- node.js - 在我的 middleware.js 文件中包含数据库访问权限