C#ASP.NET"编译器错误消息:CS1002:;期望"最基本的代码

Ste*_*ood 6 asp.net

我正在尝试测试ASP.NET是否正在我的客户IIS 7.5服务器上工作,下面的代码在我的服务器上工作正常.

<html>
<body bgcolor="yellow">
<center>
<h2>Hello</h2>
<p><%Response.Write(now())%></p>
</center>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

使用包含上述代码的完全相同的text.aspx文件,他得到错误:

Compilation Error 
Description: An error occurred during the compilation of a resource required to 
service this request. Please review the following specific error details and 
modify your source code appropriately. 

Compiler Error Message: CS1002: ; expected

Source Error:

    Line 3:  <center>
    Line 4:  <h2>Hello</h2>
    Line 5:  <p><%Response.Write(now())%></p>
    Line 6:  </center>
    Line 7:  </body>

Source File: c:\inetpub\wwwroot\myapp\test.aspx    Line: 5 
Run Code Online (Sandbox Code Playgroud)

任何想法为什么会这样?他的服务器将运行瑞士版Windows(如果这有任何区别).

非常感谢.史蒂芬

Jus*_*ner 13

您的问题是以下行:

<p><%Response.Write(now())%></p>
Run Code Online (Sandbox Code Playgroud)

由于您严格编写C#语句(而不是使用任何绑定表达式),因此该语句需要分号:

<p><% Response.Write(now()); %></p>
Run Code Online (Sandbox Code Playgroud)

哎呀...错过了部分问题.

如果这适用于本地服务器而不是客户端的远程服务器,则应确保将客户端的远程服务器设置为使用Visual Basic而不是C#作为语言.

您还可以将Language指令直接添加到*.aspx页面以强制页面使用正确的语言:

<%@ Page Title="Your page's title" Language="VB" %>
Run Code Online (Sandbox Code Playgroud)