2010-09-11 82 views
3

出于某种原因,我在尝试测试计算机上的代码页时出现此错误。ASP.NET无效元素名称StartTag错误

它可能与错误的IIS安装有关,但我似乎无法找出问题所在。

我得到以下错误:

error on line 1 at column 2: StartTag: invalid element name

这里是我的Default.aspx:

<%@ Page Language="C#" %> 

<html> 

<head> 

<title>Plating Trees</title> 

<script runat=”server”> 
protected void Page_Load(Object Source, EventArgs E) 
{ 

/* Begin C# Code!*/ 

Tree tree1 = new Tree(); 

tree1.Grow(3); 

tree1.Message(); 

} 

</script> 

</head> 

<body> 

<p><asp:label runat=”server” id=”Output” /></p> 

</body> 

</html> 

Tree.cs:

/* A simple C# class! */ 

public class Tree 
{ 

    public int height = 0; 

    public void Grow(int h) 
    { 
     height += h; 
    } 

    public string Message() 
    { 
     Output.Text = "The height of tree1 is:<br/>” + tree1.height + feet"; 
    } 

} 

回答

1

不知道这是你的问题的原因,但你的属性和代码的双引号看起来不正确。

<script runat=”server”> 
<p><asp:label runat=”server” id=”Output” /></p> 

应该是:

<script runat="server"> 
<p><asp:label runat="server" id="Output" /></p> 

Output.Text = "The height of tree1 is:<br/>” + tree1.height + feet"; 

应该是:

Output.Text = "The height of tree1 is:<br/>" + tree1.height + "feet"; 
+0

哎呦,不能相信我没有意识到, , 谢谢! – Qcom 2010-09-11 05:59:14

1

你的问题是类似的StackOverflow这个前面的问题:“StartTag: invalid element name” in default.aspx,这瑟ems就像IIS配置问题。

从链接:

When I went into the ASP.NET tab for the virtual directory I noticed the ASP.NET version was not selected (it was an empty combo box). Choosing the .NET framework version did the trick.

看一看它,它可能会解决你的问题:)

+0

谢谢,这也有帮助,但是,我仍然有问题! :)我正在努力。 – Qcom 2010-09-11 05:59:59

1

的主要问题是,你的Tree类不必Output访问,因为该属性属于不同的对象,Default.aspx。您需要拨打Output.TextDefault.aspx而不是Tree。另外,我认为杰夫是正确的关于因此,编辑您Page_Load如下:

在你的Default.aspx

<script runat="server"> 
protected void Page_Load(Object Source, EventArgs E) 
{ 
    /* Begin C# Code!*/ 
    Tree tree1 = new Tree(); 
    tree1.Grow(3); 
    Output.Text = tree1.Message(); 
} 
</script> 

Message()你需要删除Output.Text 。接下来,您不能将类Tree参考为tree1.height,因此请将其更改为this.height或最好只是height。同时,请删除feet,因为你还没有定义任何地方。请注意,此方法中也有”。最后,拿出最后的”,它位于feet的右侧。编辑如下:

在你Test

public string Message() 
{ 
    return "The height of tree1 is:<br/>" + height; 
} 

你可以把一切相同,但就个人而言,我会移动<script runat="server">块略低于<%@ Page Language="C#" %>

另外,我认为你的逻辑存在错误,但是我相信,一旦你通过这些东西,你就可以知道这一点。

(我跑从我的VS 2008 IDE)

+0

谢谢,你的意思是我的逻辑错误?你是说我设置超级简单的“程序”的方式? – Qcom 2010-09-11 06:00:35

+0

@BOSS:我的意思是说,当我运行它时,输出不是你想要的,因为你的'Message()'方法仍然关闭。查看我的解决方案更新。 – JohnB 2010-09-11 15:30:15

+0

@BOSS,就设置此程序而言,我认为大多数ASP.NET程序员更喜欢使用“代码隐藏”页面类型,因此您的方法位于名为'Default.aspx.cs'的单独文件中 – JohnB 2010-09-11 15:45:40

0

@BOSS,也许你需要运行ASPNET_REGIIS工具在IIS中重新注册ASP.NET。

进入您的.NET框架命令提示符并运行“aspnet_regiis -i”来执行此操作。

参考:ASP.NET IIS Registration Tool (Aspnet_regiis.exe)

而且,请注意以下几点,如果你在你的IIS多的网站:

The -i flag causes the aspnet_regiis command to perform its work on every website on the box, not just the one that needs it. As the .NET framework 2.0 begins to ship there will be more developers and production servers running both version of the framework. Running the aspnet_regiis command with the -i flag will associate all websites on the box with the framework from where the command was run (there is one version of the aspnet_regiis command for every installed version of the .NET framework). It is also useful to note that the -i flag will reset auto-generated values with immediate impact on forms based logins and viewstate checksums. If you run the command with the -i flag on a live production server you may very well interupt the applications of logged in users of other applications on the same box. The “-i“ flavor of the command should never be run in a production environment unless there are no active users logged on, and all websites on the box happen to be on the same .NET framework version.

来源:Running "aspnet_regiis -i" Not Always The Best Choice

相关问题