开发者

C# ASP.NET "Compiler Error Message: CS1002: ; expected" on the most basic code

I'm trying to test if ASP.NET is working on my customers IIS 7.5 server, the code below works fine on my server.

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

Using the exact same text.aspx file containing the above code he gets the error:

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 

Any ideas why this would be? His server will be run开发者_运维问答ning a Swiss version of Windows (if that makes any difference).

Many many thanks. Steven


Your problem is with the following line:

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

The statement needs a semicolon since you're strictly writing a C# statement (rather than using any of the binding expressions):

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

Whoops...missed part of the question.

If this is working on your local server but not the client's remote server, you should make sure that the client's remote server is set to use Visual Basic instead of C# as the language.

You can also add the Language directive directly to the *.aspx page to force the page to use the correct language:

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


Check the default language setting in IIS Manager. I think you will find your local machine is set to Visual Basic and the remote server will be set to C#.

IIS 7 and later

  1. Select the web site in question
  2. Select .NET Compilation
  3. Compare the setting value for 'Default Language'

Basically your statement is Visual Basic.

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

This is the same statement in C#

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


On my setup this needs to be:

Response.Write(now());

Please note the ; on the end of the Response.Write. What version of Windows Server / ASP.NET is install?


I am working on a legacy asp.net webforms application and I got this error, multiple of them(207) and all of them on a single .aspx file. That looked quite strange. The ; has nothing to do with the file anywhere. By mistake, the file's "Build Action" changed from "Content" to "Compile". After changing the build action to Content, all the errors vanished.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜