在Net4India上传文件时出错
本文关键字:出错 文件 Net4India | 更新日期: 2023-09-27 18:15:57
我是asp.net的新手。我试图从子目录上传到根的图像。它在调试代码时工作得很好。但是当我在IIS上上传时,它给出了一个
Access to the path 'C:'inetpub'wwwroot'APBooksHosting'HomeImage'Desert.jpg' is denied.
我的目录结构:
-ROOT-books-users-create-HomePage。aspx(我尝试上传文件的页面)
-ROOT-HomeImage("这是我要上传文件的文件夹")
我正在使用这个代码来上传一个文件
namespace WebApplication1.books.users.Create
{
public partial class Homeimage : System.Web.UI.Page
{
public void upload image()
{
if (homeimguploader.HasFile)
{
String path = Server.MapPath("~/HomeImage/");
String ext = Path.GetExtension(homeimguploader.FileName);
if (ext == ".jpg" || ext == ".png" || ext == ".gif")
{
homeimguploader.SaveAs(path + homeimguploader.FileName);
homeimage = homeimguploader.FileName;
}
}
}
}
}
对于权限问题,可以使用以下代码:
// Get full permissons
var permission = new FileIOPermission(FileIOPermissionAccess.Write, "Full Physical Path Here");
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
//your code here
}