How will you kill a user's session variable explicitly?

Wednesday, July 8, 2009






Session.Abandon()





What base class do all Web Forms inherit from?






System.web.UI.Page class.





Which Authentication methods are based on cookies?






1. Forms
2. Passport





Which Authentication method require Active Directory?






Digest.





What area the differences between Global.asax and Web.Config?

Differences between global.asax and web.config


























Sno
global.asax
web.config
1 Class File Its an XML file
2 There can be only one for an application there can be many if under different sub-folders
3
Can have Application
and Session events

Can't
4
Need
to be recompiled when changes are made
No need to compile
when changes are made.


 


 

Class implementing Interface

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

namespace OppTest2
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

Can we leave a virtual function in an abstract class without implementing in the derived class

Does c# support pure virtual function?
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();

}

Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.

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

namespace OppTest4
{
abstract class abTest
{
public abstract void a();

}

class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}

public void x()
{
Console.Out.Write("x");
}
}

class Program
{
static void Main(string[] args)
{
}
}
}

Does C# (.NET) support partial implementation?

Does C# (.NET) support partial implementation?
No.

the following program will throw an error.

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

namespace OPPTest3
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}

}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

Does C# (.NET) support partial implementation?

Does C# (.NET) support partial implementation?
No.

the following program will throw an error.

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

namespace OPPTest3
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}

}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

how to implement a pure virtual function in c#?

how to implement a pure virtual function in c#?

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

namespace OppTest4
{
abstract class abTest
{
public abstract void a();

}

class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}

public void x()
{
Console.Out.Write("x");
}
}

class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}

If A is the base class and B inherits B and C inherits B and an object is created for C , whats order of constructor

If A is the base class and B inherits B and C inherits B and an object is created for C , then what will be the order of
the constructor being called?

A then B then C.

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

namespace OopTest5
{
class A
{
public A()
{
Console.Out.Write("A");
}

}

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

}

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

}


class Program
{
static void Main(string[] args)
{
C c = new C();
Console.In.Read();
}
}
}

interface ,the class which implemented it and its object, with interface in left hand side during creation

If a class IA is implementing an interface I which is having a method a, then
can is the following allowed? Will that have all the methods of IA apart from that of interface I?

I a = new IA();

Yes. always the base class or interface can contain derived class, but it will have
only those of the base. So it will not have members of IA which are not from interface I.

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

namespace OOPTest6
{
interface I
{
void a();
}

class IA : I
{
public void a()
{
Console.Out.Write("a");
}
public void nonintfacemeth()
{
Console.Out.Write("nonintfacemeth");
}


}


class Program
{
static void Main(string[] args)
{
I i = new IA();
i.a();

}
}
}

How to call a base class constructor from a derived class?

How to call a base class constructor from a derived class?

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

namespace OOPTest7
{
class A
{
public A()
{
Console.Out.Write("base A");
}
public A(string s)
{
Console.Out.Write(s);
}

}

class B : A
{

public B() : base("base cons called from Derived")
{
Console.Out.Write("B");
}

}



class Program
{
static void Main(string[] args)
{
B b= new B();
Console.In.Read();
}
}
}

what does '()' denote in the object creation statement

what does '()' denote in the object creation statement?

It denotes the constructor.

What are test cases you should go through in unit testing?






You need to check 3 test cases, which are the following,

1. Positive test cases (correct data, correct output)

2. Negative test cases (broken or missing data, proper handling)

3. Exception test cases (exceptions are thrown and caught properly)





What are the different Debugging tools which come with .NET ?

What are the different Debugging tools
which come with .NET



Two debugging tools come with .NET, they are :


1. CorDBG
– command-line debugger


2.  DbgCLR – graphic debugger.

What are the differences between const and readonly ?

Differences between const and readonly


























Sno
const
readonly
1 Can't be static. Can be instance level or static
2 evaluated at design time evaluated at run time
3
Initialized at declaration

Initialized at declaration and in constructor
4
must be of integral type or enumeration
In addition it can have complex types with new keyword and
enumerations are not allowed


 

How can you tell the application to look for assemblies at the locations other than its installed location?





You can do that by adding the following entry in the web.config file,


<probing privatePath="c:\yourlibrary; bin\debug" />



How to read and write from a text file using c#.net ?

See the following sample,

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ReadWriteFromTxt
{
class Program
{
static void readFile()
{
FileStream fsEmp = new FileStream("c:\\Emp.html", FileMode.Open, FileAccess.Read);
StreamReader srEmp = new StreamReader(fsEmp);
string s;
while ((s = srEmp.ReadLine()) != null)
{
Console.WriteLine(s);
Console.Read();
}
srEmp.Close();
fsEmp.Close();
}

static void writeFile()
{
FileStream fsEmp = new FileStream("c:\\Emp.html", FileMode.Open, FileAccess.Write );
StreamWriter swEmp = new StreamWriter(fsEmp );

string s="Have you seen god? Is there anything else to see";
swEmp.WriteLine(s);
swEmp.Close();
fsEmp.Close();

}


static void Main(string[] args)
{
writeFile();
readFile();
}
}
}

How to download webpage using asp.net and c# ?

See the following code,

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;

namespace DownloadingFile
{
class Program
{
static void Main(string[] args)
{
WebRequest reqFile = WebRequest.Create("http://www.codecollege.net/2009/07/cloud-computing.html");

WebResponse resFile = reqFile.GetResponse();

Stream smFile = resFile.GetResponseStream();
// Output the downloaded stream to the console
StreamReader sr = new StreamReader(smFile);
string line;
while ((line = sr.ReadLine()) != null)
Console.WriteLine(line);
Console.Read();
}
}
}

What’s the difference between authentication and authorization?





what is Authentication?


Is a process by which the system decides whether the user is valid to login to the site as a whole.


what is Authorization?


Is a process by which the system decides which are the areas and functionalities the user is allowed to access, at the component level.



How to read and write from a text file using c#.net ?

See the following sample,

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ReadWriteFromTxt
{
class Program
{
static void readFile()
{
FileStream fsEmp = new FileStream("c:\\Emp.html", FileMode.Open, FileAccess.Read);
StreamReader srEmp = new StreamReader(fsEmp);
string s;
while ((s = srEmp.ReadLine()) != null)
{
Console.WriteLine(s);
Console.Read();
}
srEmp.Close();
fsEmp.Close();
}

static void writeFile()
{
FileStream fsEmp = new FileStream("c:\\Emp.html", FileMode.Open, FileAccess.Write );
StreamWriter swEmp = new StreamWriter(fsEmp );

string s="Have you seen god? Is there anything else to see";
swEmp.WriteLine(s);
swEmp.Close();
fsEmp.Close();

}


static void Main(string[] args)
{
writeFile();
readFile();
}
}
}

what are the Differences between Abstract Class and Interface ?

Difference between Abstract Class and Interface





























Sno Abstract
Class
Interface
1 Can have implemented Methods Cant
2 A class can inherit only one abstract class A Class can implement any number of Interfaces.
3 We go for Abstract classes on such situations
where we need to give common functionality for group of related classes
We go for Interface on such situations where we
need to give common functionality for group of un-related classes
4 If you add a new method, then you can provide a
default implementation and so no need to make any change to existing work.
If you add a new method, then you need to change
all the existing work.
5
Static and Instance constants are possible.
Only
Static  constants are possible.


 


 

What is web.config.? How many web.config files can be allowed to use in an application?


1.    
 

The Web.Config file is the configuration file for
asp.net web application or a web site. prefix="o" ?>



2.    
 

You can have as many Web.Config files as you want
, but there can be only one web.config file in a single folder.

What are asynchronous callbacks in .net?

It means that a call is made from a Main Program to a .net Class’s method and the program continues execution. When the callback is made ( means the method has finished its work and returns value) , the Main program handles it.

How to call a user controls method from its parent?

For example the name of your control be a SecureLoginControl and the solution be MyControls and the method you are going to call is SecuredAuthentication(), then the coding you need to do is ,

Control declaration:
Public MyControls.SecureLoginControl objSecureLoginControl ;

When calling:
boolean b;
b=objSecureLoginControl.SecuredAuthentication();

or you can call like this also,

((SecureLoginControl)Panel1.FindControl("objSecureLoginControl")).SecuredAuthentication();

What is Serialization ? What are the Types of Serialization and their differences?

Serialization:
It is the process of converting an object to a form suitable for either making it persistent or tranportable.
Deserialization is the reverse of this and it converts the object from the serialized state to its original state.

Types:
1. Binary
2. XML

Differences:













Sno Binary XML
1

It preserves type fidelity , which is useful for preserving


the state of the object between transportation and invocation.


It doesnt preserves type fidelity and hence state cant be


maintained.

2 As it is the open standard its widely used Not that much compared to
Binary.

What is assemblyInfo.cs file? Where can I find it? What is it for?

What
It consists of all build options for the project,including verison,company name,etc.
Where
It is located in the Properties folder.
Use
It is used to manage the build settings.

What is the name of the class used to read and get details of the files uploaded to asp.net?





System.Web.HttpPostedFile

What are the uses of Views?





1. Views are virtual tables (they dont store data physically) which gives a result
of data by joining tables. So you are not storing redundant data.


2. Views are used to produce reports from data


3. Views can be used to provide security to data by giving access only to views.



Blog Widget by LinkWithin