日期:2014-05-20  浏览次数:20433 次

入门第一题,是代码原因还是网站原因?
今天刚刚下载了Microsoft   Visual   Web   Developer   2005   express   edition,开始学习asp.net,碰到问题请教大家:

<%@   Page   Language= "C# "   %>
<%@   Import   Namespace= "System.IO "   %>
<%@   Import   Namespace= "System.Text "   %>

<!DOCTYPE   html   PUBLIC   "-//W3C//DTD   XHTML   1.0   Transitional//EN "   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<script   runat= "server ">

        protected   void   Button1_Click(object   sender,   EventArgs   e)
        {
                TextBox1.Text   =   "hello测试 ";
                StreamWriter   sw   =   File.AppendText(AppDomain.CurrentDomain.BaseDirectory   +   "jilu.txt ");
                if   (File.Exists( "jilu.txt "))
                {
                        sw.WriteLine(TextBox1.Text);
                        sw.Close();
                }
                else
                {
                        StreamWriter   sr   =   File.CreateText( "jilu.txt ");
                        sw.WriteLine(TextBox1.Text);
                        sr.Close();
                        sw.Close();
                }

        }
</script>

<html   xmlns= "http://www.w3.org/1999/xhtml "   >
<head   runat= "server ">
        <title> Untitled   Page </title>
</head>
<body>
        <form   id= "form1 "   runat= "server ">
        <div>
                &nbsp; <asp:TextBox   ID= "TextBox1 "   runat= "server "   Width= "178px "> </asp:TextBox> &nbsp;
                <asp:Button   ID= "Button1 "   runat= "server "   Height= "21px "   OnClick= "Button1_Click "   Text= "Button "
                        Width= "54px "   /> </div>
        </form>
</body>
</html>

调试保存成 "test.aspx "文件后,在本地测试没有问题,但上传到我购买的虚拟主机的一个子目录里面后,用浏览器打开,点击“Button”按钮后出现:
“/”应用程序中的服务器错误。
--------------------------------------------

运行时错误  

而如果将StreamWriter等写入文件的代码删除则没有问题,请教这是什么原因呢?还请前辈们指教!!谢谢


------解决方案--------------------