System.UnauthorizedAccessException的 [英] System.UnauthorizedAccessException

查看:159
本文介绍了System.UnauthorizedAccessException的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim filePath As String = "~/Images/FleaMarket/uploadedImages/" & User.Identity.Name.ToString & "/" & itemID & Path.GetExtension(fuImage.FileName)
        MsgBox(filePath)
        If fuImage.HasFile Then
            If Directory.Exists(Server.MapPath("~/Images/FleaMarket/uploadedImages/" & User.Identity.Name.ToString & "/")) = False Then
                Directory.CreateDirectory(Server.MapPath("~/Images/FleaMarket/uploadedImages/" & User.Identity.Name.ToString & "/"))
            End If
            'lblMessage.Text = ""
            If checkFileType(fuImage.FileName) Then

                fuImage.SaveAs(Server.MapPath("../Images/FleaMarket/uploadedImages/" & User.Identity.Name.ToString))

我得到一个错误的System.UnauthorizedAccessException:对路径D:\\ TriceDealsII更新\\ 13-10-11 \\ Tricedeals II(4)\\图片\\ Fleamarket跳蚤市场\\ uploadedImages \\ mitali2054'被拒绝

为什么?

推荐答案

ASP.NET应用程序,这在IIS中运行使用分配给指定的应用程序池的用户。对于每一个应用程序池将有一个Windows用户是Windows组IIS_IUSRS的一部分。由于这种用户/组没有写/更改访问到你的web应用的目录(或任何其他目录),您必须手动授予这些权限。

ASP.NET Applications, which run in IIS use the User assigned to the specified Application Pool. For each Application Pool there will be a Windows User which is part of the Windows Group "IIS_IUSRS". As this User / Group do not have Write/Change Access to the directory of your Webapplication (or any other directory) you must manually grant these permissions.

为了更好地实现这样的:在资源管理器中指定的路径,在那里你希望写你的文件浏览/数据打开目录的安全页面添加您的应用程序池的用户或组IIS_IUSRS到列表中,选择写入(或改变)权限。

To achive this: Navigate in the explorer to the specified path, where you wish to write your files / data open the Security Page of the directory to add the User of your AppPool or the Group "IIS_IUSRS" to the List and select the write (or change) permission.

请注意:写权限始终是一个安全隐患。因此,你应该尽可能多的限制就越好。

Note: Write permission is always a security risk. Therefore you should restrict it as much as possible.

这篇关于System.UnauthorizedAccessException的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆