将图像从ASP.NET上传到godaddy文件系统

Ale*_*oke 6 c# asp.net

我的网站上有一个管理员面板,允许用户将图像上传到文件系统.我只是在做C#代码:

imageFile.SaveAs(galleryPath + fileName); 
Run Code Online (Sandbox Code Playgroud)

但获得权限异常:

访问路径'D:\ Hosting ...\html\Images\Gallery\page2-img1.jpg'被拒绝.

描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.异常详细信息:System.UnauthorizedAccessException:拒绝访问路径'D:\ Hosting ...\html\Images\Gallery\page2-img1.jpg'.

能否请给我一个提示我如何授予权限?

Flo*_*ind 0

好的,这是我的观点

    @using (Html.BeginForm("Upload", "Pictures", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    <div>
    Title:<br/>
    @Html.EditorFor(x => x.Title)<br/>
    @Html.ValidationMessageFor(x => x.Title)<br/>
    @Html.TextBoxFor(x => x.File, new { 
    type = "file"
    })<br/> 
    @Html.ValidationMessageFor(x => x.File)<br/> 
    Description:<br/>
    @Html.TextAreaFor(x => x.Description)<br/>
    @Html.ValidationMessageFor(x => x.Description)
    </div>
    <div style="clear:both"></div>
    <p><input type="submit" value="Save"/></p>
}
Run Code Online (Sandbox Code Playgroud)

这是我的视图模型

public class UploadModel
    {
        [Required(ErrorMessage=("You have not selected a file"))]
        public HttpPostedFileBase File { get; set; }
        [Required(ErrorMessage = "Please enter a title")]
        [StringLength(50)]
        public string Title { get; set; }
        [StringLength(400)]
        public string Description { get; set; }
    }
Run Code Online (Sandbox Code Playgroud)

这是我的控制器操作。

    [Authorize(Roles = "Approved")]
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Upload(UploadModel m)
    {
        byte[] uploadedFile = null;
        Byte123 xxx = new Byte123();
        if (m.File != null && !string.IsNullOrEmpty(m.Title))
        {
            //var fileName = System.IO.Path.GetFileName(m.File.FileName);
            //string c = m.File.FileName.Substring(m.File.FileName.LastIndexOf("."));
           // m.Title = m.Title.Replace(c, "");
            uploadedFile = new byte[m.File.InputStream.Length]; //you get the image as byte here but you can also save it to file.
Run Code Online (Sandbox Code Playgroud)

这是 MVC 代码。如果您使用 Web 表单,那么代码应该更短。我从链接中得到了这个,但现在找不到它,所以只是发布了我自己的代码。您还需要确保使用 Cpanel 在主机中启用了写入权限。