异常详细信息: system.unauthorizedaccessexception: 对路径“c:\inetpub\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>
