IsPost Property in ASP.NET & HTTP GET and POST Methods

The HTTP protocol (used for web pages) supports a very limited number of methods (verbs) that are used to make requests to the server. The two most common ones are GET (which is used to read a page), and POST (which is used to submit a page). In general, the first time a user requests a page, the page is requested using GET. If the user fills in a form and then clicks a submit button, the browser makes a POST request to the server.

In web programming, it's often useful to know whether a page is being requested as a GET or as a POST so that you know how to process the page. In ASP.NET Web Pages, you can use the IsPost property to see whether a request is a GET or a POST. If the request is a POST, the IsPost property will return true, and you can do things like read the values of text boxes on a form.

Explain the services provided by the .Net Framework

The .NET Framework is a managed execution environment that provides a variety of services to its running applications. It consists of two major components: the Common Language Runtime (CLR), which is the execution engine that handles running applications; and the .NET Framework Class Library, which provides a library of tested, reusable code that developers can call from their own applications.
The services that the .NET Framework provides to running applications include the following:


  • Memory Management - In .NET Framework applications, the CLR is responsible for allocating and releasing memory and for handling object lifetimes on behalf of the application.
  • Common Type System - In the .NET Framework, basic types are defined by the .NET Framework type system and are common to all languages that target the .NET Framework. This fecilitates cross-language interoperability.
  • Extensive Class Library - Programmers can use a readily accessible library of types and their members from the .NET Framework Class Library, instead of writing vast amounts of code to handle common low-level programming operations.
  • Development Frameworks and Technologies - The .NET Framework includes libraries for specific areas of application development, such as ASP.NET for web applications, ADO.NET for data access, and Windows Communication Foundation for service-oriented applications.
  • Language Interoperability - Language compilers that target the .NET Framework emit an intermediate code named Common Intermediate Language (CIL), which, in turn, is compiled at run time by the Common Language Runtime. With this feature, routines written in one language are accessible to other languages, and programmers can focus on creating applications in their preferred language or languages.
  • Version Compatibility - With rare exceptions, applications that are developed by using a particular version of the .NET Framework can run without modification on a later version.
  • Side-by-Side Execution - The .NET Framework helps resolve version conflicts by allowing multiple versions of the common language runtime to exist on the same computer. This means that multiple versions of applications can also coexist, and that an application can run on the version of the .NET Framework with which it was built.
  • Multitargeting - By targeting the .NET Framework Portable Class Library, developers can create assemblies that work on multiple .NET Framework platforms, such as Windows 7, Windows 8, Windows Phone, and Xbox 360.

Glossary


Term
Definition
.NET Framework
The .NET Framework is a component of the Windows operating system that provides the programming model for building, deploying and running Web-based applications, smart client applications and Web services. The .NET Framework consists of the common language runtime (CLR) and a unified class library.
Active Directory
The Windows directory service that provides a unified, hierarchical view of complex networks.
ADO.NET
The suite of data access technologies included in the .NET Framework class libraries
ASP.NET
The development component for building server-based Web applications. An evolution of ASP into the .NET Framework.
Assembly
The primary building block—also the unit of deployment and versioning—of a .NET Framework application. An assembly includes an assembly manifest, which describes the contents of the assembly
C#
A new ECMA-approved programming language designed for the .NET Framework. C#, which is an evolution of C and C++, is type safe and object oriented. Because it is compiled as managed code, it benefits from the services of the common language runtime, such as language interoperability, enhanced security, and garbage collection.
Class Library, .NET Framework
A library of classes, interfaces, and value types that are included in the Microsoft .NET Framework and can be used from any CLS-compliant language. The .NET Framework class library provides access to system functionality and is designed to be the foundation on which .NET Framework applications, components, and controls are built.
Common Language Runtime (CLR)
The engine at the core of .NET Framework-managed code execution. The runtime supplies managed code with services such as cross-language integration, code access security, object lifetime management, and debugging and profiling support.
Common Language Specification (CLS)
A subset of .NET Framework features that are supported by a broad set of compliant languages and tools. CLS-compliant languages and tools are guaranteed to interoperate with other CLS-compliant languages and tools.
ECMA
A European standards body created in 1961. Internationally accredited ECMA has fast-track approval for ISO and is the forum for successful standards such as ECMAScript.
Evidence-Based Security
The .NET Framework introduces the concept of evidence-based security, referring to inputs to the security policy about code—such as from what site, security zone, or URL was an assembly obtained, what is its strong name, and whether it has a digital signature and from whom. Based on these and other answers—which can come from multiple sources depending on where the code is run—the appropriate security policy can be applied, and the appropriate permissions may be granted to the assembly..
Extensible Markup Language (XML)
A subset of Standard Generalized Markup Language (SGML) that is optimized for delivery over the Web. XML provides a uniform method for describing and exchanging structured data that is independent of applications or vendors.
Garbage Collection (GC)
The process of transitively tracing through all pointers to actively used objects to locate all objects that can be referenced and then arranging to reuse any heap memory that was not found during this trace. The CLR garbage collector also compacts the memory that is in use to reduce the working space needed for the heap.
HTTP
Hyper Text Transfer Protocol is a standard Internet protocol for transfer of information between servers and between clients and servers.
IDL
Interface Definition Language. A language used by applications to specify the various interfaces they intend to offer to other applications.
Microsoft intermediate language (MSIL)
A language used as the output of a number of compilers and as the input to a just-in-time (JIT) compiler, which produces native code. MSL defines an abstract, stack-based execution model.
JIT
An acronym for "just-in-time", a phrase that describes an action that is taken only when it becomes necessary, such as just-in-time compilation or just-in-time object activation.
Loosely Coupled Architecture
A distributed application in which you can change the implementation of one tier without affecting any of the other tiers. Contrast tightly coupled architecture.
Managed Code
Managed code supplies the metadata necessary for the CLR to provide services, such as memory management, cross-language integration, code access security, and automatic lifetime control of objects. All code based on MSIL executes as managed code.
Manifest
An integral part of every assembly that renders the assembly self-describing via metadata. The metadata describes which modules and resource files are part of a particular assembly, which types are exported, and which other assemblies are referenced. It also specifies which security permissions are required to run, what additional permissions are optionally requested, and what permissions the assembly refuses.
Metadata
Data (or information) about data. Many different systems use metadata—for example, type libraries in COM provide metadata and databases have schemas. In the CLR, metadata is used to describe assemblies and types. It is stored with them in the executable files, and is used by compilers, tools, and the runtime to provide a wide range of services. Metadata is essential for runtime type information and dynamic method invocation.
Native Code
Code that has been compiled to processor-specific machine code.
n-tier
System architecture that separates presentation, business logic, data access, and database (or other persistence mechanism) tiers.
Reflection
.NET Framework technology that allows you to examine metadata that describes types and their members. Reflection can be used to create, invoke, and access type instances at run time.
Serviced Component
The mechanism that enables COM+ services to be available to .NET Framework classes.
Side-by-Side Execution
The ability to run multiple versions of the same assembly simultaneously. This can be on the same computer or in the same process or application domain. Allowing assemblies to run side-by-side is essential to support robust versioning in the common language runtime. Side-by-side is also used to describe to describe two versions of the .NET Framework running simultaneously on the same computer.
SOAP
Simple Object Access Protocol, a W3C standard. A lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML-based protocol for exchanging structured and type information on the Web. The SOAP protocol contains no application or transport semantics, which makes it highly modular and extensible.
Tightly Coupled Architecture
A distributed application where a change to any tier affects some or all the other remaining tiers. Contrast loosely coupled architecture.
UDDI
Universal Description, Discovery, and Integration (UDDI) specification. An initiative that creates a global, platform-independent, open framework to enable Web service providers to advertise the existence of their Web services and for Web service consumers to locate Web services of interest.
Unmanaged Code
Code that was created without knowledge for the conventions and requirements of the .NET Framework. Unmanaged code executes in the .NET Framework environment with minimal services (for example, no garbage collection, limited debugging, and no declarative security).
Web forms
The ASP.NET page framework, which supports server-side controls that render HTML user interface on Web browsers.
Web services
A programming model that provides the ability to exchange messages in a scalable, loosely coupled, and platform-neutral environment using standard protocols such as HTTP, XML, XSD, SOAP, and WSDL. The SOAP-based XML messages exchanged between a Web service and its clients can be structured and typed, or loosely defined. The flexibility of using a text format such as XML enables the message exchange to evolve over time in a loosely coupled way. Because they are based on standard protocols and are platform neutral, Web services enable communication with a broad variety of implementations, platforms, and devices.
Web Services Description Language (WSDL)
An XML-based contract language for describing network services offered by a server.
Windows Forms
A rich Windows client library that encapsulates native Win32 APIs and exposes secure, managed classes for creating smart Windows client applications. The Windows Forms class library provides many controls, such as buttons, check boxes, drop-down lists, combo boxes, data grid, and others, that encapsulate user-interface and other client-side functionality.
Windows Management Instrumentation (WMI)
A component of the Windows operating system that provides management information and control in an enterprise environment using industry-wide standards.
WSDL
(see Web Services Description Language)
XML
(see Extensible Markup Language).
XML Schema Definition (XSD)
A W3C Recommendation that specifies how to formally describe the elements of an XML document. The schema can be used to verify the conformance of elements in an XML document.

Page Life Cycle - Guess the correct answer

In which stage of general page life cycle, 'IsPostBack' property is set?

1) Page Request
2) Start
3) Load
4) Validation
5) Rendering


Answer: Option 2: Start

Explanation: In the Start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property.

External Link: Page Life Cycle in ASP.NET

Virtual Methods / Method Overriding - Guess the Output

class A
{
    public virtual void ABC()
    {
        Console.WriteLine("A");
    }
}

class B : A
{
    public override void ABC()
    {
        Console.WriteLine("B");
    }
}

class C: B
{
    new public virtual void ABC()
    {
        Console.WriteLine("C");
    }
}

class X
{
    public static void Main()
    {
        A a = new C();
        B b = new C();
        C c = new C();

        a.ABC();
        b.ABC();
        c.ABC();
    }
}


Option 1: ABC
Option 2: BBA
Option 3: BBC
Option 4: AAB
Option 5: Error

Answer: Option 3: BBC

Explanation: While overriding, the type of object determine which method to be called. Method overriding is a feature that allows us to invoke functions (that have the same signatures) that belong to different classes in the same hierarchy of inheritance using the base class reference. C# makes use of two keywords: virtual and override to accomplish method overriding.

The method ABC() of base class A is declared as virtual, while the derived class's implementation of ABC() is decorated with override modifier. This enables C# to invoke methods like ABC() based on objects the reference variable refers to and not the type of reference that is invoking the function.

Hence in the above program when the instances "a" and "b" refers to the object of class C, the code goes to its base class B, since class B overrides the method ABC of its base class A, method ABC of class B is invoked in both the cases.

When create an object of type C and assign its reference to reference variable "c", ABC() method of class C is executed because the reference variable c refers to the object of class C.

Static Members - Guess the Output

public class ABC
{
    public static string Description
    {
        get { return "Class ABC implemented"; }
    }
    public string GetDescription()
    {
        return Description;
    }
}

public class BCD : ABC
{
    public new static string Description
    {
        get { return "Class BCD implemented"; }
    }
}

class program
{
    static void Main(string[] args)
    {
        Console.WriteLine(new BCD().GetDescription());
        Console.ReadKey();
    }
}


Option 1: Class ABC implemented
Option 2: Class BCD implemented
Option 3: Error

Answer: Option 1: Class ABC implemented

Explanation: Static members are relevant to types and not to instances. 

In this case, return Description; always returns the value of Description property of class ABC type.

Enumeration - Guess the Output

public enum eFormDetailType
{
    eInitialize = 1, eClear, eDelete, eFill
}

public static void Main()
{
    try
    {
        eFormDetailType FormDetailTypeItem = (eFormDetailType) 5;
        Console.WriteLine(FormDetailTypeItem);
    }
    catch
    {
        Console.WriteLine("It's an EXCEPTION");
    }
}

What is the output?

Answer: 5

Explanation: 5 does not have an enumeration to cast against, therefore the output will be 5. If another enum like "eSave" was added in, then the output would be "eSave".

Guess the correct output - OOPS Inheritance (Base Class, Sub-Class)

class A
{
    B objBA = new B();
    public A()
    {
        Console.Write("A");
    }
}

class B
{
    public B()
    {
        Console.Write("B");
    }
}

class C : A
{
    B objB = new B();
    public C()
    {
    Console.Write("C");
    }   
}

class program
{
    static void Main(string [] args)
    {
        new C();
    }
}

Option 1: C
Option 2: BC
Option 3: BCBA
Option 4: BABC
Option 5: BBAC

Answer: Option 5: BBAC

Explanation: Base class constructor will be invoked before derived class constructor.
First constructor of class B will be called, then the execution transfers to class A, where constructor of class B will be called again, then constructor of class A will be called. At Last constructor of class C will be invoked.
So, the output comes to BBAC.

Inheritance (Base Class, Sub-Class) - What is the output?

public class A
{
    public A()
    {
        Console.WriteLine("Class A");
    }
}

public class B : A
{
    public B()
    {
        Console.WriteLine("Class B");
    }
}

public class C : B
{
    public C()
    {
        Console.WriteLine("Class C");            
    }
}

C objC = new C();

Option 1: Class A
Option 2: Class B
Option 3: Class C
Option 4: Class C Class B Class A
Option 5: Class A Class B Class C

Answer: Option 5: Class A Class B Class C


Explanation: Constructors that are declared within a base class, are not inherited by sub-classes. As with any other class, a sub-class with no constructors defined is provided with a default constructor, that provides no explicit functionality.
The constructors from the base class are not made available when creating new sub-class object instances. When a sub-class is instantiated, the standard behavior is for the default constructor of the base class to be called automatically.
In this way the base constructor can initialize the base class before the sub-class' constructor is executed.

What are the different types of literals in C#?

  • Boolean literals: True and False are literals of the Boolean type that map to the true and false state, respectively.
  • Integer literals: Used to write values of types int, uint, long, and ulong.
  • Real literals: Used to write values of types float, double, and decimal.
  • Character literals: Represents a single character and usually consists of a character in quotes, such as 'z'.
  • String literals: C# supports two types of string literals, regular string literal and verbatim string literals. A regular string literal consists of zero or more characters enclosed in double quotes, such as "224568". A verbatim string literal consists of an @ character followed by a double–quote character, such as ©"hello".
  • Null literal: Represents the null–type.

SQL - How can you display monthly information starting from current month to last month in the period?

Recently I was working on a project, in which I need to display cumulative monthly information for all the years in the period starting from the current month to the month for end of the period (if less that 12 months) or all the months (is more than 12 months).

I searched Internet, but I was not able to get any substantial help. So, I finally decided to write it down myself:

--------------------------Variable Declaration Start-----------------------------
DECLARE @in_website_id int, @in_surgeon_id int,  @in_customer_type_id int, @in_selection_criteria_id int
DECLARE @vc_marketing_channel varchar(100), @vc_campaign_id_sf varchar(40)
DECLARE @dt_start varchar(20), @dt_end varchar(20), @dt_start_compare varchar(20), @dt_end_compare varchar(20)
--------------------------Variable Declaration End-------------------------------
SET @in_website_id = 6
SET @in_surgeon_id = 0
SET @in_customer_type_id = 0
SET @in_selection_criteria_id = 0
SET @vc_marketing_channel = 'Website-Affiliate-PY'
SET @vc_campaign_id_sf = ''
SET @dt_start = '11/01/2011'
SET @dt_end = '04/30/2012'
SET @dt_start_compare = '11/01/2011'
SET @dt_end_compare = '04/30/2012'
--------------------------Stored Procedure Start---------------------------------
SELECT in_month_id AS in_month, ISNULL(SUM(dc_estimated_net_roi), 0) AS dc_estimated_net_roi
INTO #temp_current
FROM dbo.cd_process_data
WHERE in_website_id = @in_website_id AND in_surgeon_id = @in_surgeon_id
AND (((@vc_marketing_channel <> 'Email Marketing') AND (vc_marketing_channel = @vc_marketing_channel))
OR ((@vc_marketing_channel = 'Email Marketing') AND (vc_marketing_channel = @vc_marketing_channel AND vc_campaign_id_sf = @vc_campaign_id_sf)))
AND in_customer_type_id = @in_customer_type_id AND in_selection_criteria_id = @in_selection_criteria_id
AND ((in_year_id = YEAR(@dt_start) AND in_month_id >= MONTH(@dt_start))
OR ((in_year_id > YEAR(@dt_start) AND in_year_id < YEAR(@dt_end)) AND (in_month_id >= 1 AND in_month_id <= 12))
OR ((in_year_id > YEAR(@dt_start)) AND (in_year_id = YEAR(@dt_end)) AND (in_month_id >= 1 AND in_month_id <= MONTH(@dt_end)))
OR ((in_year_id = YEAR(@dt_start)) AND (in_year_id = YEAR(@dt_end)) AND (in_month_id >= MONTH(@dt_start) AND in_month_id <= MONTH(@dt_end))))
GROUP BY in_month_id

SELECT in_month_id AS in_month, ISNULL(SUM(dc_estimated_net_roi), 0) AS dc_estimated_net_roi
INTO #temp_previous
FROM dbo.cd_process_data
WHERE in_website_id = @in_website_id AND in_surgeon_id = @in_surgeon_id
AND (((@vc_marketing_channel <> 'Email Marketing') AND (vc_marketing_channel = @vc_marketing_channel))
OR ((@vc_marketing_channel = 'Email Marketing') AND (vc_marketing_channel = @vc_marketing_channel AND vc_campaign_id_sf = @vc_campaign_id_sf)))
AND in_customer_type_id = @in_customer_type_id AND in_selection_criteria_id = @in_selection_criteria_id
AND ((in_year_id = YEAR(@dt_start_compare) AND in_month_id >= MONTH(@dt_start_compare))
OR ((in_year_id > YEAR(@dt_start_compare) AND in_year_id < YEAR(@dt_end_compare)) AND (in_month_id >= 1 AND in_month_id <= 12))
OR ((in_year_id > YEAR(@dt_start_compare)) AND (in_year_id = YEAR(@dt_end_compare)) AND (in_month_id >= 1 AND in_month_id <= MONTH(@dt_end_compare)))
OR ((in_year_id = YEAR(@dt_start_compare)) AND (in_year_id = YEAR(@dt_end_compare)) AND (in_month_id >= MONTH(@dt_start_compare) AND in_month_id <= MONTH(@dt_end_compare))))
GROUP BY in_month_id

CREATE TABLE #temp_main (in_month int, dc_current_estimated_net_roi decimal(12, 2), dc_previous_estimated_net_roi decimal(12, 2))

INSERT INTO #temp_main (in_month)
SELECT in_month FROM #temp_current

INSERT INTO #temp_main (in_month)
SELECT in_month FROM #temp_previous WHERE in_month NOT IN (SELECT in_month FROM #temp_main)

UPDATE a SET a.dc_current_estimated_net_roi = ISNULL((SELECT dc_estimated_net_roi FROM #temp_current WHERE in_month = a.in_month), 0)
FROM #temp_main a

UPDATE a SET a.dc_previous_estimated_net_roi = ISNULL((SELECT dc_estimated_net_roi FROM #temp_previous WHERE in_month = a.in_month), 0)
FROM #temp_main a

SELECT DATENAME(MONTH, in_month * 28) AS vc_month, FLOOR(ROUND(dc_previous_estimated_net_roi, 0)) AS [Last Period],
FLOOR(ROUND(dc_current_estimated_net_roi, 0)) AS [Current Period]
FROM #temp_main
ORDER BY (MONTH(GETDATE()) - in_month) % 12  -- starting from Current Month to the Last Month from Current

DROP TABLE #temp_current
DROP TABLE #temp_previous
DROP TABLE #temp_main
--------------------------Stored Procedure End-----------------------------------

For report from Current Month to the Last Month from Current in the given period in SQL Query, we use ORDER BY ((MONTH(GETDATE()) - in_month) + 12) % 12. This is the key which does this trick.

Ex: Let us assume that the current month is March.

Current Date: 03/04/2013
@dt_start = '08/01/2011'
@dt_end = '04/30/2012'

Output Months Order:

March
February
January
December
November
October
September
August
April

Note: Notice that the month starts from March and decreases gradually.


If we require report from One Month before Current Month to the Last Month from Current, we can use the following text in the SQL Query:

ORDER BY ((MONTH(GETDATE()) - (in_month + 1)) + 12) % 12

Ex: Let us assume that the current month is March.

Current Date: 03/04/2013
@dt_start = '08/01/2011'
@dt_end = '04/30/2012'

Output Months Order:
February
January
December
November
October
September
August
April
March

Note: Notice that the month starts from February and decreases gradually.


If we require report from End Month of the period to Last Month from End Month of the period, we can use the following text in the SQL Query:

ORDER BY ((MONTH(@dt_end) - in_month) + 12) % 12

Ex: Let us assume that the current month is March.

Current Date: 03/04/2013
@dt_start = '08/01/2011'
@dt_end = '04/30/2012'

Output Months Order:
April
March
February
January
December
November
October
September
August

Note: Notice that the month starts from April and decreases gradually.