Showing posts with label ASP.NET with C#. Show all posts
Showing posts with label ASP.NET with C#. Show all posts

Explain the term authentication with respect to ASP.Net securrity.


  • Authentication is the process of obtaining identification credentials such as name and password from a user and validating those credentials against same authority.
  • If the credentials are valid, the entity that submitted the credentials is considered an authenticated identity.
There are three ways of doing authentication and authorization in ASP.NET:
  • Windows authentication: In this methodology ASP.NET web pages will use local windows users and groups to authenticate and authorize resources.
  • Forms Authentication: This is a cookie-based authentication where username and password are stored on client machines as cookie files or they are sent through URL for every request. Form-based authentication presents the user with an HTML-based Web page that prompts the user for credentials.
  • Passport Authentication: Passport authentication is based on the passport website provided by the Microsoft. So when user logins with credentials it will be reached to the passport website (i.e. hotmail, devhood, windows live etc) where authentication will happen. If Authentication is successful it will return token to your website.
  • Anonymous access: If you do not want any kind of authentication then you will for Anonymous access.
To enable a specified authentication provider for an ASP.NET application, you must create an entry in the application's configuration file as follows:
    // web.config file
    <authentication mode = "[Windows/Forms/Passport/None]">
    </authentication>

What is type casting? Explain the concept of Boxing and Unboxing.


Type casting is converting one type of data to another type. For eg., converting from string to int or vice versa. In C#, type casting has two forms:

  • Implicit Type conversion: These conversions are performed by C# in a type-safe manner. For example, conversions from smaller to larger integral types and conversions from derived classes to base classes.
  • Explicit Type conversion: These conversions are done explicitly by users using the pre-defined functions. Explicit conversions require a cast operator.
C# boxing and unboxing
    C# Type system contains three types they are called Value types, Reference Types and Pointer Types. C# allows us to convert a value type to a reference type, and back again to value type. The operation of converting a value type to a reference type is called Boxing and the reverse operation is called Unboxing.

Boxing:
  1. int Val = 10;
  2. Object Obj = Val; //Boxing
The first line we created a Value type Val and assigned a value to Val. The second line, we created an instance of Object Obj and assign the value of Val to Obj. From the above operation (Object Obj = Val) it comes to know that converting a value of a Value Type into a value of a corresponding Reference Type. These types of operation is known as Boxing.'

Unboxing:
  1. int Val = 10;
  2. Object Obj = Val; //Boxing
  3. int i = (int)Obj; //Unboxing
The first two line is about boxing a Value Type. The third line (int i = (int)Obj ) extracts the Value type from the Object. That is converting a value of a reference type into a value of Value type. This operation is known as Unboxing.

What is AJAX. How is the processing of a web page without AJAX different from the processing of a web page with AJAX?


  • AJAX stands for Asynchronous JavaScript and XML, which is a way of transferring data between the dedicated server hosting and client without sending the entire page, and thereby creating a complete postback.
  • This allows for a richer experience for the user, since dynamic content can be done in the background without refreshing and redrawing the entire page.
Processing of a web page without AJAX
  • Traditional page processing model has few drawbacks. As the entire page is loaded after postback, the HTML sent to the browser is much larger than it needs to be. Even though only part of the page is changed after postback complete page gets refreshed.
  • Because the entire page is replaced, the browser has to dismiss the old one and then draw the new one. This causes the page to 'flicker' which results in an unattractive user experience.
  • AJAX technology is deployed to overcome these two problems.
Processing of a web page with AJAX
  • Create flicker-free pages that enable you to refresh portions of the page without a full reload and without affecting other parts of the page.
  • Provides feedback to users during these page refreshes.
  • Update sections of a page and call server-side code on a scheduled basis using a timer.
  • Access server-side web services and the page methods and work with the data they return.
  • Use the rich client-side programming framework to access and modify elements in the page, and get access to code model and type system that looks similar to that of the .NET framework.

Differentiate between overloading and overriding in C#.


Overloading Overriding
Having same method name with different signatures. Methods name and signatures must be same.
Overloading is the concept of compile time polymorphism. Overriding is the concept of runtime polymorphism.
Two functions having same name and return type, but with different type and/or number of arguments is called Overloading. When a function of base class is re-defined in the derived class called as Overriding.
It doesn't need inheritance. It needs inheritance.
Method can have different data types. Method should have same data type.
Method can have different access specifier. Method should be public.
class abc
{
 public void Disp(int a)
 {  
  Console.WriteLine(a);
 }
 public void Disp(int a, int b)
 {  
  Console.WriteLine("{0}{1}",a,b);
 }
}
class Program
{
 static void Main(string[] args)
  {
   abc a1 = new abc();
   a1.Disp(10)
   Disp(10, 20);
  }
}
public class MyBaseClass
{
 public virtual void print1()
 {  
  Console.WriteLine("Base imp");
 }
}
public class MyDerivedClass:
MyBaseClass
{
 public override void print1()
 {  
  Console.WriteLine("Derived imp");
 }
}
class Program
{
 static void Main(string[] args)
 {
   MyDerivedClass myobj = new MyDerivedClass();
   MyBaseClass myBaseObj = myobj;
   myBaseObj.print1();
   Console.ReadKey();
 }
}