6

You know that C# is a compiled language. But when we develop web applications we use ASP.NET + C#, in this case can we say that ASP.NET is compiled?

If ASP.NET is not compiled does it affect the performance of C# when ASP.NET and C# works beside each other to develop web applications?

2
  • 1
    Yes, ASP.NET is compiled. If you're developing in Visual Studio, don't forget to turn off debug mode when publishing which will increase performance. Jun 16, 2011 at 17:07
  • 1
    Very confused by your question. You first state that you know that C# is a compiled language. Doesn't that answer your own question from the get go? Jun 30, 2011 at 1:40

3 Answers 3

10

Yes, ASP.NET application is being compiled into IL and run with that. Compilation either occurs at first request (that's why first request tends to take longer time than subsequent request) or can be pre-compiled at deploy.

See, for instance, http://www.informit.com/articles/article.aspx?p=1073232

6

If you utilize ASP.NET precompilation of your ASPX/ASCX files, then yes: we can say that the application is compiled.

However, if ASP.NET precompilation is not used, then there will be a performance hit when the page is loaded for the first time because ASP.NET will have to compile it on the fly. As well, the lack of precompilation means that you may not catch an error in the mark-up until a specific component of the web app is called.

For maximum performance and early detection of errors, you should always precompile ASP.NET web applications.

There are components in the mark-up that bind at runtime (rather than at compile time), such as ObjectDataSource controls, but this is no different from writing C# code to perform reflection.

The compiled result is going to be only as statically verifiable as your code (or the ASP.NET framework) uses the features of the type system. Code that breaks the type system (e.g. via late binding with reflection) will run slower and introduce errors that the compiler cannot catch.

1
  • i don't remember the specific example, but i was recently kind of surprised when I realized it was possible to inject server side tags into the markup of a page from code running early on in the lifecycle Jun 5, 2012 at 23:40
3

I assume that you are referring to the contents of the actual .aspx page containing the markup?

The .aspx page is not directly compiled. Instead, at runtime the ASP.NET engine generates C# code based on this file, places it in a folder called, "Temporary ASP.NET Files", and then compiles that C# code. So yes, it is compiled.

There is a bit about it in this post: https://stackoverflow.com/q/2374086/158483

You can also enable precompilation to make this compilation already at compile time. But it is still being compiled if you don't enable precompilation. It is just being compiled much later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.