• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

ASP.NET c# 文件上传

发布: 2007-7-01 11:09 | 作者: admin | 来源: | 查看: 36次 | 进入软件测试论坛讨论

领测软件测试网 异常详细信息: System.UnauthorizedAccessException: 对路径“C:\.netpub\spatial\csk\Communities\Common\Images\HtmlTextBoxUserImages\logo.gif”的访问被拒绝。

ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。ASP.NET 有一个在应用程序没有模拟时使用的基进程标识(通常,在 IIS 5 上为 {MACHINE}\ASPNET,在 IIS 6 上为网络服务)。如果应用程序正在通过 <identity impersonate="true"/> 模拟,则标识将为匿名用户(通常为 IUSR_MACHINENAME)或经过身份验证的请求用户。

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

源错误:

行 23: 行 24: //改变下面的“c:\\"到你想要保存的地址。 行 25: myFile.PostedFile.SaveAs("C:\\Inetpub\\spatial\\csk\\Communities\\Common\\Images\\HtmlTextBoxUserImages\\"+newnm) ; 行 26: 行 27: //取得上传文件的各种属性。

<%--
upload.aspx
这是一个上传文件,从中我们可以看出asp.net的优势,以前需要控件才能完成的程序,现在只需要几行代码就可以轻松完成。
--%>
<%@ Import Namespace="System.IO" %>
<%@ page Language="C#" debug="true" codepage="936"%>

<html>
<head>
<title>文件上传,aspcool.com </title>
<script language="C#" runat="server">

public void UploadFile(object sender , EventArgs E)
{

if(myFile.PostedFile!=null)
{
//定义一些变量
string nam = myFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
string newnm =nam.Substring(i) ;


//改变下面的“c:\\"到你想要保存的地址。
myFile.PostedFile.SaveAs("C:\\Inetpub\\spatial\\csk\\Communities\\Common\\Images\\HtmlTextBoxUserImages\\"+newnm) ;

//取得上传文件的各种属性。
fname.Text=myFile.PostedFile.FileName;
fenc.Text=myFile.PostedFile.ContentType ;
fsize.Text=myFile.PostedFile.ContentLength.ToString();


}
}

</script>
</head>
<body>
<center>
<h3> 文件上传演示</h3>
<form id="uploderform" method="post" action="upload.aspx" enctype="multipart/form-data" runat="server" >

<table border="1" cellspacing="0" cellpadding="0" >
<tr> <td><h5>选择文件</h5></td</tr>
<tr><td>
<input type="file" id="myFile" runat="server" >
</td></tr>
<tr><td>
<input type="button" value="Upload" OnServerClick="UploadFile" runat="server" >
</td></tr>
</table>
</form>
<br>
<br>
<table border="1" cellspacing="0">
<tr><td><b>文件资料</b></td>
<td> </td>
</tr>
<tr>
<td>文件名称 :</td>
<td><asp:label id="fname" text="" runat="server" /></td></tr>
<tr>
<td>文件类型 :</td>
<td><asp:label id="fenc" runat="server" /></td></tr>
<tr>
<td>文件大小 :(in bytes)</td>
<td><asp:label id="fsize" runat="server" /></td></tr>
</table>
<br>
<br>
<br>
<h5>你可以从 <a href="http://www.aspcool.com/download">http://www.aspcool.com/download</a> 下载该程序.我们将给您提供更多的其它程序。如果有什么意见请到我的<a href="http://www.chaxiu.com/club/right.php?boardid=7&page=1">ASP论坛</a>来讨论。</h5>
</center>
</body>
</html>

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网