2010-10-18 101 views
6

我试图测试ASP.NET是否在我的客户IIS 7.5服务器上工作,下面的代码在我的服务器上正常工作。C#ASP.NET“编译器错误消息:CS1002:;预计”在最基本的代码

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

使用包含上面的代码,他获得误差完全相同的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 

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

很多很多,谢谢。 Steven

回答

13

你的问题是与以下行:

<p><%Response.Write(now())%></p> 

的语句需要一个分号,因为你严格编写C#声明(而不是使用任何绑定表达式):

<p><% Response.Write(now()); %></p> 

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

如果这是在您的本地服务器上工作,但不在客户端的远程服务器上,则应确保客户端的远程服务器设置为使用Visual Basic而不是C#作为语言。

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

<%@ Page Title="Your page's title" Language="VB" %> 
+0

它为什么在我的服务器上工作?谢谢 – 2010-10-18 15:42:22

+0

@Steven - 看我的编辑。我错过了这部分问题。被代码分心了。 :-P – 2010-10-18 15:44:51

+0

很好的答案,感谢您的帮助。 – 2010-10-18 15:59:10

3

检查IIS管理器中的默认语言设置。我想你会发现你的本地机器被设置为Visual Basic,远程服务器将被设置为C#。

IIS 7和更高

  1. 选择有问题的网站
  2. 选择.NET编译
  3. 为 '默认语言'

基本上你的发言比较设定值是Visual Basic。

<%= Response.Write("Blah") %> 

这是在C#中相同的语句

<%= Response.Write("Blah"); %> 
0

在我的设置这必须是:

的Response.Write (现在());

请注意;在Response.Write的结尾。什么版本的Windows Server/ASP.NET被安装?