我如何在ASP.NET MVC3中上传文件 [英] How do i upload a file in asp.net mvc3

查看:78
本文介绍了我如何在ASP.NET MVC3中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试在asp.net mvc应用程序中上载文件时,都会出现此错误.谁能帮我吗.引发的错误是System.UnauthorizedAccesException

拒绝访问路径"C:\ inetpub \ wwwroot \ IBGTxalert \ TxAlert \ TxAlert.Web \ Files \ linqtoexcel.xlsx".

i get this error anytime i try to upload a file in my asp.net mvc application. Can anyone help me out. The error thrown is a System.UnauthorisedAccesException

Access to the path ''C:\inetpub\wwwroot\IBGTxalert\TxAlert\TxAlert.Web\Files\linqtoexcel.xlsx'' is denied.

推荐答案

尝试在非授予的wwwroot文件夹中写入/上传文件.在
捕获此类亚硒酸盐异常的最佳实践
You are trying to write/upload a file in the non granted wwwroot folder. Itz best practice to capture these kinds of securite exception at
try
{
    ... Upload code ...
}
catch (System.UnauthorizedAccessException ex)
{
    ... handles exception ..
}



没有授权ASP.NET访问请求的资源.考虑将资源的访问权限授予ASP.NET请求标识. ASP.NET具有一个基本进程标识(在IIS 5上通常为{MACHINE} \ ASPNET或在IIS 6上通常为Network Service),如果应用程序无法模拟,则使用该标识.

要授予ASP.NET对文件的访问权限,请在资源管理器中右键单击该文件,选择属性",然后选择安全性"选项卡.单击添加"以添加适当的用户或组.突出显示ASP.NET帐户,然后选中所需访问权限的框.



ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.


这篇关于我如何在ASP.NET MVC3中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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