.net文件上传到在线服务器,但只在运行时显示代码

时间:2017-09-26 06:40:09

标签: c# asp.net .net server

我已将Default.aspxPrecompiledApp.configweb.config上传到我服务器中的文件管理器,但是当我调用Default.aspx时,它会在浏览器中显示文件代码。

<%@ page language="C#" autoeventwireup="true" inherits="_Default, App_Web_jpizvube" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
// <![CDATA[

        function category_onclick() {

        }

        function fromM_onclick() {

        }

// ]]>
    </script>
</head>
<body>
<form runat=server>
   <table border="2" cellpadding="10px" cellspacing="10px">
  <tr>

    <td colspan="2" align="center"><h3>Register New Customer</h3>
    </td>
  </tr>

<tr>
<td>Choose Category
</td>
<td>



    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>

    </td>
  </tr>


  <tr>
  <td>Choose Subcategory
  </td>
   <td> 
       <asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True"
           onselectedindexchanged="DropDownList4_SelectedIndexChanged">
       </asp:DropDownList>




  </td>

  </tr>

  <tr>
  <td>Choose lowersubcategory
  </td>
   <td> 

       <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True">
       </asp:DropDownList>

  </td>
  </tr>



    <tr>
    <td> Choose Location
    </td>
    <td>


        <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" 
            onselectedindexchanged="DropDownList2_SelectedIndexChanged">
        </asp:DropDownList>
</td>
  </tr>

    <tr>
    <td>Longitude<br/><br/>
    Latitude 
    </td>
    <td>
        <asp:TextBox ID="TextBox1" runat="server"  AutoPostBack="True" ></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server"  AutoPostBack="True" ></asp:TextBox>
    </td>
  </tr>

    <tr>
    <td>Name
    </td>
    <td>

        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </td>
  </tr>

    <tr>
    <td>Address
    </td>
    <td>
        <asp:TextBox ID="TextBox4" runat="server" TextMode="MultiLine"></asp:TextBox>

    </td>
  </tr>


    <tr>
    <td>Image
    </td>
    <td>
        <asp:FileUpload ID="FileUpload1" runat="server" />

    </td>
  </tr>


     <tr>
    <td>Contact Number
    </td>
    <td>
        <asp:TextBox ID="TextBox5" runat="server" ></asp:TextBox>

    </td>
  </tr>

  <tr>
    <td>Website
    </td>
    <td>
        <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>

    </td>
  </tr>

 <!--<tr>
    <td>
    </td>
    <td>
    </td>
  </tr>-->
  <tr>

  <td>Working Hours</td>
  <td>
  <label>Monday to Friday</label>
      <asp:CheckBox ID="CheckBox1" runat="server" />
      <asp:DropDownList ID="DropDownList9" runat="server">
          <asp:ListItem Value="6:00AM"></asp:ListItem>
          <asp:ListItem Value="6:30AM"></asp:ListItem>
          <asp:ListItem Value="7:00AM"></asp:ListItem>
          <asp:ListItem></asp:ListItem>
      </asp:DropDownList>



 <label>to</label>

<asp:DropDownList ID="DropDownList10" runat="server">
    <asp:ListItem>6:00AM</asp:ListItem>
      </asp:DropDownList>


  <br />
  <br />
  <label>Saturday</label>
      <asp:CheckBox ID="CheckBox2" runat="server" />

      <asp:DropDownList ID="DropDownList5" runat="server">
      </asp:DropDownList>


 <label>to</label>

      <asp:DropDownList ID="DropDownList8" runat="server">
      </asp:DropDownList>
<br />
<br />
<label>Sunday</label>
      <asp:CheckBox ID="CheckBox3" runat="server" />

      <asp:DropDownList ID="DropDownList6" runat="server">
      </asp:DropDownList>
 <label>to</label>

      <asp:DropDownList ID="DropDownList7" runat="server">
      </asp:DropDownList>

  </td>
  </tr>


   <tr>
    <td colspan="2" align="center">
        <asp:Button ID="btn_Submit" runat="server" Text="Register" 
            onclick="btn_Submit_Click" />
    &nbsp;&nbsp;&nbsp;
    <input type="reset" value="Cancel"/>
    </td>

  </tr>

</table>
</form>
</body>
</html>

请帮我正确部署,当我在上传到服务器后尝试相同的文件时,这个代码在visual studio中运行良好,它在浏览器中显示了这个源代码。

2 个答案:

答案 0 :(得分:0)

您的服务器似乎不支持.aspx MIME扩展。您需要配置IIS。请使用此链接 - http://thesolving.com/server-room/how-to-install-and-configure-iis-on-windows-server-2012-r2/

答案 1 :(得分:-1)

您需要向IIS注册ASP.NET Handler,为此您需要运行aspnet_Regiis.exe,尝试使用管理员权限运行该命令。 exe的位置在c:\ Windows \ Microsoft.NEt \ Framework \ v4.0.30319

aspnet_regiis -i

您可以在此处https://msdn.microsoft.com/en-us/library/k6h9cz8h.aspx

详细了解相关信息