我正在尝试测试ASP.NET是否正在我的客户IIS 7.5服务器上运行,下面的代码在我的服务器上工作正常。
<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(如果这有任何区别)。
非常感谢。 史蒂芬
答案 0 :(得分:13)
您的问题出在以下几行:
<p><%Response.Write(now())%></p>
该语句需要分号,因为您严格编写C#语句(而不是使用任何绑定表达式):
<p><% Response.Write(now()); %></p>
哎呀...错过了部分问题。
如果这在本地服务器上工作但在客户端的远程服务器上不起作用,则应确保客户端的远程服务器设置为使用Visual Basic而不是C#作为语言。
您还可以将Language指令直接添加到* .aspx页面,以强制页面使用正确的语言:
<%@ Page Title="Your page's title" Language="VB" %>
答案 1 :(得分:3)
检查IIS管理器中的默认语言设置。我想你会发现你的本地机器设置为Visual Basic,远程服务器将设置为C#。
IIS 7及更高版本
基本上你的语句是Visual Basic。
<%= Response.Write("Blah") %>
这是C#
中的相同陈述<%= Response.Write("Blah"); %>
答案 2 :(得分:0)
在我的设置中,这需要是:
回复于(现在());
请注意;在Response.Write的末尾。安装了哪个版本的Windows Server / ASP.NET?