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

I am trying to check if ASP.NET is working on my IIS 7.5 client 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 same text.aspx file containing the above code, it gets an 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? Its server will run on the Swiss version of Windows (if that matters).

Many thanks. Stephen

+6
source share
3 answers

Your problem is related to the following line:

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

The operator needs a semicolon, since you strictly write the C # operator (instead of using any binding expressions):

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

Oops ... the missing part of the question.

If this works on your local server, but not on the remote client server, you must make sure that the remote client server is set to 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 title" Language="VB" %> 
+13
source share

Check the default language setting in IIS Manager. I think you will find that your local computer is configured on Visual Basic and the remote server will be installed in C #.

IIS 7 and later

  • Select the appropriate website
  • Choose .NET Compilation
  • Compare the default language setting

Basically your operator is Visual Basic.

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

This is the same operator in C #

 <%= Response.Write("Blah"); %> 
+3
source share

In my setup this should be:

Response.Write (now ());

Pay attention to; at the end of Response.Write. What version of Windows Server / ASP.NET is installed?

0
source share

All Articles