Friday, 1 July 2011

, ,

Can we use multiple web.config files

One can work with more then one web.config file in asp.net, but only one web.config in each folder. 

On top of the every configuration files there will be a machine.config file which will have all system wide configuration settings.

You can find this file in your OS drive like C:/windows/Microsoft.NET/vFrameworkNumber/Config folder.

One can override those settings in web.config file from your application root folder. 

Same way you can add more web.config file in sub-folder and can override the setting of parent folder web.config file.

Sunday, 5 June 2011

, ,

Extention Methods

  • This is a new feature in C# 3.0
  • Extension methods allow an existing type to be extended with new methods without altering the definition of the original type.
  • An extension method is a static method of a static class, where the this modifier is applied to the first parameter.
  • The type of the first parameter will be the type that is extended.

Example 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Extention_Methods
{
    class Program
    {
        static void Main(string[] args)
        {
            string language = "malayalam";
            Console.WriteLine(language.MyCustomMethod());
            Console.ReadLine();
        }
    }

    static class StringUtils
    {
        public static int MyCustomMethod(this string input)
        {
            return (input.Length);
        }
    }
}

Ref : here

Monday, 16 May 2011

,

Explain cookies

  1. Cookies is a small text file sent by web server and saved by web browser on client machine.
  2. Common use of cookies is to remember last logged in time of a visitor.
  3. Usually cookies are not used to store sensitive information's like passwords without prior encryption as they are just a plain text.
  4. Cookie size is limited to 4096 bytes. So cookies are used to store small amounts of data, often just user id.
  5. Also, number of cookies is limited to 20 per website. If you make new cookie when you already have 20 cookies, browser will delete oldest one.

To check if a browser accepts cookies, use below code in C# :

if (Request.Browser.Cookies)
{
     // Cookies supported
}
else
{
     // Web browser not supports cookies
}



Ref : here

Sunday, 15 May 2011

,

Avoid viewstate tampering

Viewstate store's value in a hidden field, Developer are keen to know on how to avoid someone from tampering viewstate data.
One should encrypt the view-state data to avoid someone from tampering it.
To encrypt use the below code in webconfig.  
<system.web>
      <pages ViewStateEncryptionMode="Always" />
</system.web>

Ref : here, here

Wednesday, 30 March 2011

Difference between Equal() and ==

  • Equals() method compares the state of an object i.e. it compares the contents of the two objects.
  • == compares the instance of the object i.e. it comparing the identifier(references).

Example :
 
string s1 = "test";
string s2 = "test";
string s3 = new string(new char[] { 't', 'e', 's', 't' });
object s4 = s3;
Console.WriteLine("{0} {1} {2}", object.ReferenceEquals(s1, s2), s1 == s2, s1.Equals(s2));
Console.WriteLine("{0} {1} {2}", object.ReferenceEquals(s1, s3), s1 == s3, s1.Equals(s3));
Console.WriteLine("{0} {1} {2}", object.ReferenceEquals(s1, s4), s1 == s4, s1.Equals(s4));

Output :

True True True
False True True
False False True

Ref: here, here

Monday, 28 March 2011

Difference between Abstract classes and Interface

  • Abstract Class
    • A class may inherit only one abstract class.
    • An abstract class can contain access modifiers for the subs, functions, properties.
    • An Abstract class has abstract or concrete subs, functions, properties etc.
    • An abstract class can have fields and constants defined.
 
    • Interface
      • A class may inherit several interfaces, which help achieving Multiple Inheritance.
      • An interface cannot have access modifiers for the subs, functions, properties etc everything is assumed as public
      • An interface can only have abstract subs, functions, properties etc
      • No fields can be defined in interface
    Ref- here, here

    Saturday, 26 March 2011

    Types of sql statements

    • DML
      • DML is abbreviation of Data Manipulation Language.
      • Examples: UPDATE, INSERT, DELETE statements
    • DDL
      • DDL is abbreviation of Data Definition Language.
      • Examples: CREATE, ALTER, DROP statements
    • DCL
      • DCL is abbreviation of Data Control Language.
      • Examples: GRANT, REVOKE statements
    • TCL
      • TCL is abbreviation of Transactional Control Language.
      • Examples: COMMIT, ROLLBACK statements
    • DQL
      • DQL is abbreviation of Data Query Language.
      • Examples: SELECT statements
    Ref: here

    What's Trending?

    Text Widget 2

    Interview Gossip. Powered by Blogger.

    Followers