新手,问个很菜的问题

sevenatm 2008-10-10 03:45:56
本人完全新手,想在网页里加一个投票功能,只好在网上收罗,找到一个投票代码[Asp.net简单投票系统源码],可是点击[投票]以后页面显示错误。查了字典也没看懂,希望大家帮我看看,这说的是什么意思,怎么解决。我先谢谢大家了~




页面显示如下:

Server Error in '/' Application.
--------------------------------------------------------------------------------

Access to the path 'D:\123\App_Data\savepoll.dat' is denied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.UnauthorizedAccessException: Access to the path 'D:\123\App_Data\savepoll.dat' is denied.

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. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

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.

Source Error:


Line 60: Image3.Width = (int)(poll3ratio * 100);
Line 61:
Line 62: BinaryWriter bw2 = new BinaryWriter(new FileStream(Path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
Line 63: bw2.Write(poll1);
Line 64: bw2.Write(poll2);


Source File: d:\123\pollresult.aspx.cs Line: 62

Stack Trace:


[UnauthorizedAccessException: Access to the path 'D:\123\App_Data\savepoll.dat' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +651
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1038
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +114
pollresult.Page_Load(Object sender, EventArgs e) in d:\123\pollresult.aspx.cs:62
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +43
System.Web.UI.Control.OnLoad(EventArgs e) +98
System.Web.UI.Control.LoadRecursive() +71
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4300




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
...全文
356 37 打赏 收藏 转发到动态 举报
写回复
用AI写文章
37 条回复
切换为时间正序
请发表友善的回复…
发表回复
toury 2008-10-14
  • 打赏
  • 举报
回复
楼主,我上传了一个资料,但我自己现在看不到;你可以进你的空间--资源,查找:投票调查 ASP例找一下
sevenatm 2008-10-14
  • 打赏
  • 举报
回复
我搜索以你用户名上传的文件,只有一个[dfx_viewer_vbsource 0 不用autocad 察看dxf 文],可能是服务器有延时我再等等。
sevenatm 2008-10-14
  • 打赏
  • 举报
回复
太谢谢LS了!
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
是啊~我没开发工具
toury 2008-10-13
  • 打赏
  • 举报
回复
[Quote=引用 29 楼 sevenatm 的回复:]
昂~ 我没有UI界面~只是在本机加了IIs,在实验这个代码。
[/Quote]

开发工具里有UI界面,你不会是用NOTEPAD编辑代码吧,呵呵
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
昂~ 我没有UI界面~只是在本机加了IIs,在实验这个代码。
toury 2008-10-13
  • 打赏
  • 举报
回复
顺便说下,你要增加控件,最好不要用复制它代码的形式,而是到UI界面直接添加控件,这样系统会自己把相关的资源添加进去
toury 2008-10-13
  • 打赏
  • 举报
回复
严格的说,你的代码不是ASP,是.NET,你直接进入高级阶段啦:)

我没有你的源码工程,所以也不知道你的资源在什么地方定义或修改,自己根据红色部分线索找找看吧,哈
[EndOfStreamException: Unable to read beyond the end of the stream.]
System.IO.__Error.EndOfFile() +54
System.IO.BinaryReader.FillBuffer(Int32 numBytes) +2818904
System.IO.BinaryReader.ReadInt32() +47
pollresult.Page_Load(Object sender, EventArgs e) in d:\123\pollresult.aspx.cs:47
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
谢谢LS,我才接触asp基本上什么也不会写,这个代码也是从网上下的。
你说的[相关资源]怎么改动啊?
toury 2008-10-13
  • 打赏
  • 举报
回复
System.IO.BinaryReader.ReadInt32() +47
查一下和47有关的定义,还有资源;你只在程序里手工复制了控件或代码,相关资源你不做改动吗?
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
额~
sy_binbin 2008-10-13
  • 打赏
  • 举报
回复
不太了解这个程序的原理

所以这个问题不太好回答你!
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
在线等啊~为啥我一直在线,可不显示我在线状态呢?
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
这是一个页面调查代码,原本是3个选项,我想改成4个选项,就在原来代码后面相应地方按前一段开始加,不知道加的对不对,运行不了,高手帮我看看因为什么显示错误,谢谢了。
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
这是pollresult.aspx.cs 文件代码 我改动的地方都标注了


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
//该源码下载自www.51aspx.com(51aspx.com)

public partial class pollresult : System.Web.UI.Page
{
float poll1ratio = 0F;
float poll2ratio = 0F;
float poll3ratio = 0F;
float poll4ratio = 0F; 我加的

protected void Page_Load(object sender, EventArgs e)
{
Image1.Height = 15;
Image2.Height = 15;
Image3.Height = 15;
Image4.Height = 15; 我加的
int i = int.Parse(Request.QueryString["result"].ToString());
string Path = Server.MapPath("/App_Data/savepoll.dat");
if (!File.Exists(Path))
{
FileStream fs = File.Create(Path);
fs.Close();
BinaryWriter bw1 = new BinaryWriter(new FileStream(Path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
bw1.Write(010);
bw1.Write(010);
bw1.Write(010);
bw1.Write(010); 我加的
bw1.Close();

}
else
{
BinaryReader br = new BinaryReader(new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
int poll1 = br.ReadInt32();
int poll2 = br.ReadInt32();
int poll3 = br.ReadInt32();
int poll4 = br.ReadInt32(); 我加的
if (i == 0) poll1++;
else if (i == 1) poll2++;
else if (i == 2) poll3++;
else if (i == 3) poll4++; 我加的
br.Close();

int pollsum = poll1 + poll2 + poll3 + poll4;
poll1ratio = Convert.ToSingle((float)poll1 / pollsum);
lbyes.Text = Math.Round((poll1ratio * 100), 2).ToString() + "%";
poll2ratio = Convert.ToSingle((float)poll2 / pollsum);
lbno.Text = Math.Round((poll2ratio * 100), 2).ToString() + "%";
poll3ratio = Convert.ToSingle((float)poll3 / pollsum);
lbunknow.Text = Math.Round((poll3ratio * 100), 2).ToString() + "%";
poll4ratio = Convert.ToSingle((float)poll4 / pollsum); 我加的
llbunknow.Text = Math.Round((poll4ratio * 100), 2).ToString() + "%"; 我加的
lbsum.Text = pollsum.ToString();

Image1.Width = (int)(poll1ratio * 100);
Image2.Width = (int)(poll2ratio * 100);
Image3.Width = (int)(poll3ratio * 100);
Image4.Width = (int)(poll4ratio * 100); 我加的

BinaryWriter bw2 = new BinaryWriter(new FileStream(Path, FileMode.Open, FileAccess.Write, FileShare.ReadWrite));
bw2.Write(poll1);
bw2.Write(poll2);
bw2.Write(poll3);
bw2.Write(poll4); 我加的
bw2.Close();
}
}
}
sy_binbin 2008-10-13
  • 打赏
  • 举报
回复
没代码啊!
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
问题又出来了
我改动了一下 pollresult.aspx.cs 文件

结果出现这个错误提示

Server Error in '/' Application.
--------------------------------------------------------------------------------

Unable to read beyond the end of the stream.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IO.EndOfStreamException: Unable to read beyond the end of the stream.

Source Error:


Line 45: int poll2 = br.ReadInt32();
Line 46: int poll3 = br.ReadInt32();
Line 47: int poll4 = br.ReadInt32();
Line 48: if (i == 0) poll1++;
Line 49: else if (i == 1) poll2++;


Source File: d:\123\pollresult.aspx.cs Line: 47

Stack Trace:


[EndOfStreamException: Unable to read beyond the end of the stream.]
System.IO.__Error.EndOfFile() +54
System.IO.BinaryReader.FillBuffer(Int32 numBytes) +2818904
System.IO.BinaryReader.ReadInt32() +47
pollresult.Page_Load(Object sender, EventArgs e) in d:\123\pollresult.aspx.cs:47
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
sevenatm 2008-10-13
  • 打赏
  • 举报
回复
谢谢LS各位了,学到不少东西,知道了很多知识。
toury 2008-10-13
  • 打赏
  • 举报
回复
这样吧,回头我给你找个投票的ASP例子吧,呵呵
sy_binbin 2008-10-13
  • 打赏
  • 举报
回复


楼主先学好基础吧

没开发工具就想学习NET,不开玩笑呢吗!!
加载更多回复(17)

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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