计数器的问题!!!!!!!!!!!!请大虾们帮忙啊,在线等待。

gzhubonet 2003-09-16 11:43:46
, Boolean useAsync, String msgPath, Boolean bFromProxy) +859
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) +43
ASP.WebForm1_aspx.Page_Load(Object Sender, EventArgs e) in c:\inetpub\wwwroot\计数器1\WebForm1.aspx:19
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +29
System.Web.UI.Page.ProcessRequestMain() +724
我写了这们一段实现计数器功能的代码。
<%@ page language=vb debug=true %>
<%@ Import Namespace="System.Io"%>
<script language="vb" runat="server">
Function GetFileName() As string
Dim FullPath As string
Dim Position As Integer
FullPath=Request.ServerVariables("PATH_TRANSLATED")'获取当前路径'
Position=InstrRev(FullPath,".")
GetFileName=Mid(FullPath,1,Position)&"cnt" '生成计数器文件名'
End Function
Sub Page_Load(ByVal Sender As Object,Byval e AS EventArgs)
if not page.IspostBack then
Dim count as Integer
Dim stream As FileStream
Dim pathname,datastr as String
Dim strreadobj as StreamReader
Dim Strwriterobj as Streamwriter
pathname=GetFileName() '获取计数器文件名
stream=New FileStream(pathname,FileMode.OpenOrCreate,FileAccess.Read)
strreadobj=new StreamReader(Stream)
datastr=strreadobj.ReadLine() '读取计数文件内容
strreadobj.close()
count=CInt(datastr)
count += 1 ' 累加计数器
counter.text=count

end if
end sub
</script>
<html>
<BODY bgColor="white">
<font face="楷体_GB2312"><strong>文字计数器</strong></font>
<form runat="server" ID="Form1">
<asp:Label ID="counter" runat="server" />
</form>
</BODY>
</html>
但是编译时报这样的错:

“/计数器1”应用程序中的服务器错误。
--------------------------------------------------------------------------------

对路径“c:\inetpub\wwwroot\计数器1\WebForm1.cnt”的访问被拒绝。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.UnauthorizedAccessException: 对路径“c:\inetpub\wwwroot\计数器1\WebForm1.cnt”的访问被拒绝。

未授权此 ASP.NET 进程访问所请求的资源。出于安全原因,默认的 ASP.NET 进程标识为“{machinename}\ASPNET”,它只具有有限的特权。请考虑授予该 ASP.NET 进程标识访问此资源的权限。

若要授予 ASP.NET 对文件的写访问权,请在资源管理器中右击该文件,选择“属性”,然后选择“安全”选项卡。单击“添加”以添加“{machinename}\ASPNET”用户。突出显示此 ASP.NET 帐户,在“允许”列中选中“写”框。

源错误:


行 17: Dim Strwriterobj as Streamwriter
行 18: pathname=GetFileName() '获取计数器文件名
行 19: stream=New FileStream(pathname,FileMode.OpenOrCreate,FileAccess.Read)
行 20: strreadobj=new StreamReader(Stream)
行 21: datastr=strreadobj.ReadLine() '读取计数文件内容


源文件: c:\inetpub\wwwroot\计数器1\WebForm1.aspx 行: 19

堆栈跟踪:


[UnauthorizedAccessException: 对路径“c:\inetpub\wwwroot\计数器1\WebForm1.cnt”的访问被拒绝。]
System.IO.__Error.WinIOError(Int32 errorCode, String str) +393
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize

请大虾帮忙解决。
...全文
41 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnhgj 2003-09-16
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2267/2267644.xml?temp=.7430689

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧