显示代码错误

时间:2012-10-15 08:10:14

标签: asp.net

当我尝试使用asp.net查看源代码时,我收到此错误。

拒绝访问路径'C:\ Users \ user \ Desktop \ Website1'。

任何人都想知道如何解决这个问题?

显示代码如下。我不知道如何解决这个问题。

 <%@ Page Language="C#" runat="server" Debug="true" %>
   <%@ Import Namespace="System.IO" %> 
  <script language="C#" runat="server">
void Page_Load()
{
 string filePath = 
Server.MapPath(Request.QueryString["filename"]);
FileName.Text = Request.QueryString["filename"];
FileInfo file = new FileInfo(filePath);

if (file.Extension != ".mdb" 
 && file.Extension != ".xml" 
 && file.Extension != ".exe")
{
 Code.Text = ReadFile(filePath);
 }
   else
{
  Code.Text = "Sorry you can't read a file with an extension of " + file.Extension;
}
  }

     private string ReadFile(string filepath)
    {
         string fileOutput = "";
     try
     {
        StreamReader FileReader = new StreamReader(filepath);
       //The returned value is -1 if no more characters are 
           //currently available.
      while (FileReader.Peek() > -1)
      {
        //ReadLine() Reads a line of characters from the 
          //current stream and returns the data as a string.
        fileOutput += FileReader.ReadLine().Replace("<", "&lt;").
       Replace("  ", "&nbsp;&nbsp;&nbsp;&nbsp;") 
                    + "<br />";
          }
             FileReader.Close();
         }
           catch (FileNotFoundException e)
          {
        fileOutput = e.Message;
         }
        return fileOutput;
      }
     </script>

      <html>
       <head>
     <title>code</title>
         <link rel="stylesheet" href="style1.css" type="text/css">
       </head>
        <body>
           <h1 class="pageHeader">Source Code</h1>
          <asp:label id="FileName" 
               CssClass="codeheader" Runat="server"/>
        <asp:Panel id="pnlCode" CssClass="code" 
         runat="server" Width="80%">
          <asp:label id="Code" Runat="server" />
     </asp:Panel>
    </body>
      </html>

1 个答案:

答案 0 :(得分:0)

右键点击Website1,点击属性,转到security,点击edit,然后添加network service,看看它是否解决了您的问题。