Archive for the ‘.NET General’ Category

Web Application Vs Web Site in .NET

This post has been moved here

S.No Short Description Web Site Web Application
1 Road Map Introduced in VS 2005 only

Road Map:

VS 2003 .NET 1.1 (No Website Project Type)

VS 2005 – .NET 2.0 (Introduced Web Site by replacing Web application. After there are lots of request from the customer, Microsoft released a add-in for Web Application Project Type)

VS 2008 – .NET 3.5 (Both Web Site and Web Application Present)

VS 2010 – .NET 4.0 (Both Web Site and Web Application Present)

Introduced in VS 2003 itself

Road Map:

VS Version Web Site Web Application
VS 2003 No Yes
VS 2005 Yes No (Yes – by Add-in)
VS 2008 Yes Yes
VS 2010 Yes Yes
2 Project Definition The project will contain the same file and folder structure as Website created in the Virtual directory. So the Web site can have some files which are not part of the project (such as some requirement document, design document etc.). The solution will contain only the files which are referred/required to the project.

Adv:

  1. Not necessary to keep any files which are not required (all which are in Virtual directory)
  2. Can sub-divide one ASP.NET application into multiple VS project.
  3. Easily exclude or include the project from the source code-control
3 Compilation and build outputs The build comment is used for Web Site project only to test the project and not going to be used on runtime. To run the website we required to deploy the code on the web server and relay on ASP.NET dynamic compilation to compile the pages and classes in the application. All code-behind files and stand-alone classes in the project are compiled into a single assembly (Project Name.dll) and published (copied) in the Virtual directory. So there won’t be any dynamic compilation at run time.

As the output is a single assembly, we can specify attributes such as name, version, location etc.,

4 Interactive development We can setup the build option in VS how the build must be done when we run the site. Building the site can be in three ways: 1. Build the site 2. An individual page 3. Nothing at all.

If the nothing at all option is selected, the VS simply launch the browser and passes to the current/startup page.

To run and debug pages, we must build the entire project.

Adv: Building entire web application will make the development fast, because VS employs an incremental build model. It means the VS only build the files which are changed.

5 Deployment The Publish Website command will compile the aspx and code-behind files into assemblies in VS. But the default pre-compilation produces several assemblies in Bin folder on the site (typically assembly can be vary one per page, one per folder).

The Fixed-names option produces one per page (.aspx) or user control (.ascx). These can be used to create deployable version of individual page. But it will increase no of assemblies and increased memory usage.

As all code-behind and stand-alone class files are compiled into single assemblies, only the assembly needs to be deployed into the Web server along with .aspx, .ascx files and other static content files.

The .aspx, .ascx are not compiled until they run in the browser.

6 Upgraded from VS 2003 A conversation wizard is available to upgrade existing VS 2003 Web Application project to later version Web site project. There may be manual fix-up required if the project is much complex. As VS 2003 and later versions support Web application, no requirement to convert. So simple opening the project in later version of VS will do the job.
7 Deployment of the application Deploying the full source code on the server by copying both .aspx, .aspx.cs/.aspx.vb files to the server.
It is considered as XCOPY of the source code to the Web Server.
The source code will be compiled by ASP.NET runtime compiler on the Web Server before request is getting processed.
Adv: Enable to edit the code on the server itself to fix some bugs or to enhance the system.
Disadv: There won’t be security for the code, data and application functionality.
Compile the source code in the development environment and deploy the .aspx file and compiled .dll files to the server.
So copying the full source code with .aspx.cs /.aspx.vb files is not required.
The source code will be compiled in the Visual Studio at Development Environment before deployment to the server.
Adv: Security on code, data, application functionality.
Disadv: To change a simple buy entire deployment life cycle required to follow.
8 Unit Testing on Application It is difficult to create Unit Test cases (Ex: using MBUnit, Nunit, VS Unit Test project) by referring the actual source code of the Web Site. If it very easy to create Unit Test cases (Ex: using MBUnit, Nunit, VS Unit Test project) by referring the compiled DLLs. It will also be confirmed that the Unit Test will be done on a compiled code, so no changes will be done after testing completed.
9 Changes in Visual Studio 2005 Web Site has been introduced in VS 2005 only.
It makes available of all new features of VS 2005 and ASP.NET 2.0 (like master pages, site navigation, themes, web parts, personalization, role management, membership and loginetc.,)
Removed in VS 2005 release and replaced with Web Site project Type.
It removes (Web Site) two Web application requirements:
1. Using FrontPage Server Extension (FPSE)
2. Using a local copy of IIS (but website support both IIS and build-in ASP.NET development server).
10 Code behind Model Single Page code model. When we create a page, there will be a aspx.cs/aspx.vb file associates for the page.
We can even write the same code in the .aspx file also by writing inside of <script> tag.
Multiple page code models. When creating a page, there will be a aspx.cs/aspx.vb and aspx.designer.cs/aspx.designer.vb file created.
11 Code Compilation Code will be compiled dynamically when required (request has been raised from client) and on the required page.
It allows building particular page instead of entire site.
Adv:
1. Allows runtime changes (After a page viewed, the code behind can be changed and refreshed the changes on the page without breaking the entire application)
2. In Visual Studio – the developer can get the flexibility to edit the code on debugging mode. After saving the changes, the page can be refreshed to see the changes without rebuilding the website.
Full application code will be compiled on building the Web application and no further compilation on page request from the client system.
Disad: 1. In Visual Studio – the developer will not get flexibility to change the code (it will be locked – read-only) on debugging time. To change the code, the developer required to stop the application to change the code.
12 Assembly Naming The assembly name will be decided by the VS only. The assembly names can be controlled by developer. It means the assembly will be created on the bin folder; it can be renamed as per the developer view.
13 Assembly creation There will be one assembly for each page (including .aspx, .ascx etc.,) There will be a single assembly for a Web Application project (normally ProjectName.dll)
14 Building the application It can possible to build single Web project at a time and we will not have flexibility to add reference to any other Web Site project. As Web Application can be build using multiple web projects. So a Web Application can add reference to any other Web Application and use.
15 Building the application It is not possible to add Pre-built and Post-build steps during the compilation. It is possible to add Pre-built and Post-build steps during the compilation.

It means, we can add some command line steps on pre-build and post-build event by using Properties-> Build Event Tab.

16 Copy Web Site Menu Will have Copy Web Site menu on the Web Site to connect a remote Web Site and Copy/Synchronize the files between Source Web site and Remote Web site. There won’t be any Copy Web Site option to copy the files.
17 Compilation Constrains As the pages are compiled dynamically and compiled into different assemblies, there is no requirement that entire Web site must compile successfully to run the application.

If any error occurred on a page, it will throw the error at the time when the page getting compiling/running dynamically.

As entire pages are compiled at first time and created in a single assembly, the project must compile successfully.
18 Compatibility with Web Developer Express Edition Will work well Web application projects do not work with Visual Web Developer Express Edition.

What, Why and How Garbage Collector?

You can find lots of useful information from the msdn and other webpages…

Here are some points for understanding Garbage Collector (GC)

We can say Garbage Collector is used to free the memory (to allocate for another object) used by an object when the object is not longer used.

Considering the process of the GC, we can say:
1. When we create any object using new, the runtime will allocate memory in the next available location in the heap for that object to live.

2. It will be used by our code for sometime…..

3. The object is considered as not reachable object when the object is not referred by any other object, or the object is not referring any object object, or all the reference are set to null for that object or when the execution come out of the scope

4. The Step 1 to 3 will be continuing for the object whatever creating at runtime. So the heap will be blocked by the objects.

5. The Garbage Collector (GC) decides to recollect the memory from the object when there is not enough memory for the new object creating (as per point 1).

6. The GC will collect the objects which are not longer reachable (as per point 3). Then it will move the reachable object in to the contiguous space and reclaim the memory used by other object. So the memory will be freed from the unused/unreachable object.

The collection process is fully automatic, but there are ways we can do programming to make the GC process more efficiently.

for more information, pls refer the msdn site.