2011-01-11 96 views
0

我有一些奇怪的麻烦。代码在根目录运行,但不是子目录

我有一段代码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"  Inherits="_Default" %> 

    <!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>VERSIONS CHECK!!!</title> 
    </head> 
    <body> 
     <form id="form1" runat="server"> 
     <div> 
      <asp:Label ID="lblVersion" runat="server" /> 
     </div> 
     <br /> 
     <div> 
      <asp:Label ID="lblHelloWorld" runat="server" /> 
     </div> 
     <p> 
      <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 
     </p> 
     </form> 
    </body> 
    </html> 

和代码隐藏文件:

using System; 
using System.Collections.Generic; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class _Default : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
{ 
    lblVersion.Text = System.Environment.Version.ToString(); 
} 
protected void Button1_Click(object sender, EventArgs e) 
{ 
    if (lblHelloWorld.Text.Equals(string.Empty)) 
    { 
     lblHelloWorld.Text = "Hello World"; 
    } 
    else 
    { 
     lblHelloWorld.Text = ""; 
    } 
} 
} 

此作品在本地,而在我的public_html文件夹中。但是,如果我把它放在子文件夹中,如public_html/folder1/folder2它带有一个错误。

Server Error in '/' Application. 
Runtime Error 
Description: An application error occurred on the server. The current custom error  settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine. 
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off". 
<!-- Web.Config Configuration File --> 
<configuration> 
    <system.web> 
     <customErrors mode="Off"/> 
    </system.web> 
</configuration> 
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL. 
<!-- Web.Config Configuration File --> 
<configuration> 
    <system.web> 
     <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/> 
    </system.web> 
</configuration> 

林品牌新的ASP.NET和发布与Visual Studio - 这样的机会是,即时通讯做错了什么地方。其实这是我第一次尝试写ASP.NET - 所以要温和:)

Thx提前。

杰克这是我的配置文件如何现在看起来:

在Visual Studio Asp.Net配置选项。 的设置和注释的完整列表可在 machine.config.comments通常位于 \的Windows \ Microsoft.Net \框架中找到\其中Vx.x \配置 - >

<system.web> 
    <compilation debug="true" targetFramework="4.0"> 
    </compilation> 
    <authentication mode="Windows"/> 


<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm"> 
<error statusCode="403" redirect="NoAccess.htm" /> 
<error statusCode="404" redirect="FileNotFound.htm" /> 
</customErrors> 
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/> 
</system.web> 
</configuration> 

而我现在得到的错误是:

'/'应用程序中的服务器错误。 配置错误 描述:处理服务此请求所需的配置文件时发生错误。请查看下面的具体错误细节并适当修改您的配置文件。

解析器错误消息:在应用程序级别之外使用注册为allowDefinition ='MachineToApplication'的节是错误的。此错误可能是由于虚拟目录未被配置为IIS中的应用程序。

源错误:

Line 26:    ASP.NET to identify an incoming user. 
Line 27:   --> 
Line 28:  <authentication mode="Windows"/> 
Line 29: 
Line 30: 

回答

2

好找出您收到什么样的错误,你需要看的customErrors为“关”在你的web.config文件。您可以将其设置为RemoteOnly,但我不认为您正在实际服务器框中查看它,因此请将其设置为关闭。

<customErrors mode="Off" defaultRedirect="GenericErrorPage.htm"> 

</customErrors> 

这会告诉你你收到了什么错误。

+0

我已经编辑新的东西后。 – fjappe 2011-01-11 22:44:06

+0

我试图在我的web服务器上创建一个子域(在线),它使我成为一个新的根目录,所以我现在在我的酒店的根目录中有public_html和folder1。 – fjappe 2011-01-11 22:56:18

相关问题