0

当我尝试使用 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>
4

1 回答 1

0

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

于 2012-10-15T08:13:20.673 回答