Tuesday, 21 January 2014

When I create a new ASP.NET 4 web application, the web.config file is almost empty. What happened to all the configuration elements that were there prior to ASP.NET 4?

                                                                                                                                        Previous....
                                                                                                                                                     Next.....



All the major configuration settings are moved into machine.config file, and all the applications will inherit the setting from this file. If an application needs to override the default settings, we can do so using the application specific configuration (web.config) file. ASP.NET 4 applications have clean web.config files.

If you create a new asp.net 4 empty web application, the only entry that you will find is shown below.


Note: If you create a new ASP.NET Web Application, instead of a new ASP.NET Empty Web Application, you will find a lot more confiuration entries in the web.config file. This is because, the template for ASP.NET web application overrides some of the default settings inherited from machine.config.



ASP.NET Page is very slow. What will you do to make it fast

This is a very common asp.net interview question asked in many interviews. There are several reasons for the page being slow. We need to identify the cause. 

1. Find out which is slow, is it the application or the database : If the page is executing SQL queries or stored procedures, run those on the database and check how long do they take to run. If the queries are taking most of the time, then you know you have to tune the queries for better performance. To tune the queries, there are several ways and I have listed some of them below.
   a) Check if there are indexes to help the query
   b) Select only the required columns, avoid Select *.
   c) Check if there is a possiblity to reduce the number of joins
   d) If possible use NO LOCK on your select statements
   e) Check if there are cursors and if you can replace them with joins


Difference between EnableViewState and ViewStateMode properties



1. Using EnableViewState property we only have 2 options
     We can turn off view state altogether,
                              or
     Enable viewstate for the entire page and then turn it off on a control-by-control basis.

2. If you want to turn of ViewState for the entire page and only enable it for specific controls on the page, then we have to use ViewStateModeproperty in conjunction with EnableViewState.

3. EnableViewState property only accepts true or false values and the default value is true, where as ViewStateMode property can have a value of - Enabled, Disabled and inherit. Inherit is the default value for ViewStateMode property.

4. ViewStateMode property is introduced in ASP.NET 4, where as EnableViewState exists from a long time.

5. If EnableViewState is to True, only then the ViewStateMode settings are applied, where as, if EnableViewState is set to False then the control will not save its view state, regardless of the ViewStateMode setting. In short if EnableViewState is set to False, ViewStateMode setting is not respected.

6. To disable view state for a page and to enable it for a specific control on the page, set the EnableViewState property of the page and the control to true, set the ViewStateMode property of the page to Disabled, and set the ViewStateMode property of the control to Enabled.


These are the different types of extensions in Dot Net Files 
.
» .aspx- Web Form 
» .master - Master Page 
» .ascx - WebUserControl 
» .edmx - Ado Entity data Model
» .cs - Class file
» .rpt - CrystalReport
» .xsd - DataSet1
» .ascx - DynamicDataField
» .htm - HTMLPage
» .csproj - SilverlightApplication
» .mdf - Sql Server Database
» .config - web configuration file
» .asmx -web services
» .xml - XML file
                                                                                                                                       Previous....
                                                                                                                                                     Next.....





Software development environments in asp.net

                                                                                                                                        Previous...




What are the different environments in your development process or development life cycle at your company?
This is a general interview question and not very specific to ASP.NET. Usually, the interviewer asks this question to measure your understanding of the different environments and their role in software development. Some interviewers, may also ask this question, to check if you really have the work experience you are claiming it.
 



1. Development
2. QA
3. Staging
4. UAT (User Acceptance Testing)
5. Production

1. Development Environment - All the developers check in their current work into development environment.

2. QA (Quality Assurance) Environment - This is the environment, where testers (QA) test the application. QA cannot test on development environment, because developers are continuously checking in new code. So, if there is a bug, we don't know, if it's caused by the old or new code. In short,  if development is going on in the same environment it would be difficult to keep up with the current state. There will be lot of confusion, if the developer is trying to fix in the same area as the tester is testing. Without development and QA environment being seperate their is no way to do proper testing.

3. Staging Environment - Many organisations, try to keep their staging environment as identical as possible to the actual production environment. The primary reason for this environment is to identify any deployment related issues. Also, if you are developing a B2B (Business to Business) application, you may be interfacing with other service provider systems. Many organisations, usually setup their staging environment to interface with the service providers as well, for complete end to end testing.

4. Production Environment - The actual live environment, that we use for day to day business. 

Note: In general, the code flows from Development => QA => Staging => Production

Nullable Types in C#

                                                                                                                                       Precious......
                                                                                                                                                    Next......

Nullable-: We can directly assign NULL value to the reference Type But can't assign null value to Value type so we use Nullable keyword to assign NULL value to value type variable.
1. Nullable types in C#
2. Null Coalescing Operator ??  



In C# types  are divided into 2 broad categories.
Value Types  - int, float, double, structs, enums etc
Reference Types – Interface, Class, delegates, arrays etc


By default value types are non nullable. To make them nullable use ?
int i = 0 (i is non nullable, so "i" cannot be set to null, i = null will generate compiler error)
int? j = 0 (j is nullable int, so j=null is legal)

Nullable types bridge the differences between C# types and Database types

Program without using NULL coalescing operator
using System;
class Program
{
    static void Main()
    {
        int AvailableTickets;
        int? TicketsOnSale = null;
        if (TicketsOnSale == null)
        {
            AvailableTickets = 0;
        }
        else
        {
            AvailableTickets = (int)TicketsOnSale;
        }
        Console.WriteLine("Available Tickets={0}", AvailableTickets);
    }
}


The above program is re-written using NULL coalescing operator
using System;
class Program
{
    static void Main()
    {
        int AvailableTickets;
        int? TicketsOnSale = null;
        //Using null coalesce operator ??
        AvailableTickets = TicketsOnSale ?? 0;
        Console.WriteLine("Available Tickets={0}", AvailableTickets);
    }
} 



                                                                                                                                       Precious......
                                                                                                                                                    Next......

Reading and writing to a console in C#

                                                                                                                                       Precious......
                                                                                                                                                    Next......



In this session we will learn Basic structure of a C#  programme.
In part 1  we simply print a message by using "Console.writeline" keyword. But in this part we print a message which is printed by user. If  user print  "NetQube" then it return "Hello NetQube".

Two ways to write to console
     a) Concatenation
     b) Place holder syntax – Most preferred 



Code samples used in the demo


using System;
class Program
{
    static void Main()
    {
       
        Console.WriteLine("enter your name");
        // Read the name from console
        string UserName = Console.ReadLine();
        // Concatenate name with hello word and print
        Console.WriteLine("Hello " + UserName);  // here UserName should be same because C# is a case sensitive 
        //Placeholder syntax to print name with hello word 
        //Console.WriteLine("Hello {0}", UserName);
       // here {0} is a place holder when we print user name then it substitute at {0} position
    }
}


We can Better understand by using another example
using System;
class Program
{
    static void Main()
    {
       
        Console.WriteLine("enter your FirstName");
        string FirstName = Console.ReadLine();
         Console.WriteLine("enter your  SecondName");
         string SecondName = Console.ReadLine();
        Console.WriteLine("Hello " +  FirstName , SecondName); 
        //Placeholder syntax to print name with hello word 
        //Console.WriteLine("Hello {0} , {1}", FirstName , SecondName);
       
    }
}


                                                                                                                                       Precious......
                                                                                                                                                    Next......






C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...