TechShri from Shriniwas Wani

Custom Search

31 March, 2009

Access User Control's Variable Property Inside an ASPX parent Page

Here is great way to access User control's public property inside a parent page in ASP.Net

If TotalNumberOfItemsAdded is the public property inside user control's code-behind file. And if you are setting this property in Usercontrol's code behind only then to access the property in the ASP.NET Web page:

Register the user control, make sure property is PUBLIC so that page can access it.

< uc:control id="ucntrl1" runat="server" >

Now you can access the property in your page like <%= ucntrl1.TotalNumberOfItemsAdded %>

Labels:

07 August, 2008

Download ATLAS AJAX Extension for Visual Studio .Net 2005

Download ATLAS AJAX Extension for Visual Studio .Net 2005

http://www.codeplex.com/AjaxControlToolkit/Release/ProjectReleases.aspx?ReleaseId=11121#ReleaseFiles

.exe files for different tools in the .NET SDK

Visual Studio and the .NET SDK include a number of tools to help in writing programs and
migrating existing code to the .NET environment. Among them are the following tools:

DbgCLR.exe The Microsoft CLR Debugger, a Visual Studio–like debugger with a GUI.

Cordbg.exe A command-line based runtime debugger that uses the CLR debugging
application programming interface (API).

Ilasm.exe The Microsoft Intermediate Language Assembler, which generates files in
the Portable Executable format from an intermediate language file. You can run the code
generated by this utility to test whether the intermediate code performs as expected.

Ildasm.exe A disassembler that converts a Portable Executable format file into a text file
that can be used by Ilasm.exe.

Aximp.exe An ActiveX control importing tool. This program converts the type definitions in
a COM type library for an ActiveX control into a Windows Forms control. This tool is handy for
converting existing components to the .NET Framework.

Sn.exe, Al.exe, and GacUtil.exe These three programs provide utilities to create a security
key, add the key to an assembly, and then add the assembly to the assembly cache.


caspol.exe = Code Access Security Policy Tool

permview.exe = Permissions View Tool while working with CAS

06 August, 2008

Adding reference: more about mscorlib.dll

VS.Net adds few common references when a new project is created. By default some assemblies do not need any reference. Class “console” for example is located in “mscorlib.dll”, we can use this console class directly, and we do not add reference to this assembly.

Casting in C# - Down Casting and Up casting

Casting

Assume a base class Employee and its derived classes as ContractEmployee and PermanentEmployee.

Employee e = new ContractEmployee();
// Above code will work – because there is implicit Upcaste from Derived to Base class.

ContractEmployee ce = new Employee(); // Won't compile – it’s a Downcaste


This happens because the rules of substitutability says that, a derived class object can always be used in place of Parent class object (Upcasting)
Because there's no guarantee that the object supports the interface defined by the ContractEmployee class.

Therefore,
in the case of a downcast, an explicit cast is used as follows:

ContractEmployee ce = (ContractEmployee) new Employee();

But what happens if we lie and try to trick the CTS by explicitly
casting a base class to a derived class as follows?

Employee e = new Employee();
ContractEmployee c = (ContractEmployee)e;

The result is not a compile-time error, because e might have really been an upcasted. But the true nature of the upcasted object can't be known until run time.

The CLR determines the object types at run time, therefore runtime error System.InvalidCastException.

Note : The CLR determines the object types at run time only.

There is one other way of casting objects: using the as keyword.

Advantage of using this “as” keyword instead of a cast is that
- if the cast is invalid, you don't have to worry about an exception being thrown.
- What will happen instead is that the result will be null. Here's an example:

class Employee { }
class ContractEmployee : Employee { }

class CastExampleUsingAsKeyword
{
public static void Main ()
{
Employee e = new Employee();
Console.WriteLine("e = {0}", e == null ? "null" : e.ToString());

ContractEmployee c = e as ContractEmployee;
Console.WriteLine("c = {0}", c == null ? "null" : c.ToString());
}
}

You'll see the following result:
e = Employee
c = null

30 July, 2008

Distributed Computing using .NET Remoting

Distributed Computing using .NET Remoting
By Amit Kumar Agrawal

Distributed computing has become the identity of present generation software applications. In past, developers used technologies like DCOM (Distributed Component Object Model) by Microsoft, CORBA (Common Object Request Broker Architecture) by OMG and Java RMI (Remote Method Invocation) by SUN for the same purpose.

Microsoft .Net Remoting is an extensible framework provided by Microsoft .Net Framework, which enables communication across Application Domains (AppDomain).

AppDomain is an isolated environment for executing Managed code. Objects within same AppDomain are considered as local whereas object in a different AppDomain is called Remote object. Microsoft .Net Remoting comes into picture when an application requires communication between different AppDomains.

How Remoting Works?




Just like other distribute computing technologies, in .Net Remoting also, client object doesn't make a direct call to the remote object, rather it creates a proxy object of the remoting object and then uses the proxy object to invoke methods of remote object. When the client object calls a method of remote object via proxy, the call is formatted by a formatting object (SOAP, Binary or any Custom formatter). After formatting the call is transferred to the remote object via proper channel (TCP Channel, HTTP Channel or any Custom channel) where the method is executed. Now the entire process is reversed to return appropriate result to the client object.

Figure 1: .Net remoting Architecture

Remote Object

Remote object (Located at server side) is derived from System.MarshalByRefObject class which provides required functionality for communicating with an object in different AppDomain. Any object that needs to be transferred across appDomains has to be passed by value and should implement ISerializable interface. An object which doesn't implement ISerializable interface can't be transmitted across appDomains.

Example:

using System;
namespace Employee
{
public class Employee: MarshalByRefObject
{
//Constructor
public Employee
{
// Implementation details
}
//Other functions will come here
}
}

Proxy Object

This is created when a client object activates a remote object.

We can have two types of remoting objects i.e. Client Activated Object or Server Activated Object.

Client Activated Object: Client Activated Remote object is one whose life is controlled by client object. Here one single instance of remote object will exist per client object. Client Activated Object is created using new keyword. Client Activated object can store state information for a specific client.

Server Activated Object: Contrary to Client Activated Remote objects, life time for Server Activated Object is controlled by Server. These objects are created when client object calls a method on the proxy object. There are two types of Server Activated Objects i.e. SingleCall and Singleton.

SingleCall: They serve only one client request. Once the client request is over, they are subjected to garbage collection. They don't store any state information.

Singleton: They serve multiple clients, thereby allowing information sharing between requests. They are stateful objects unlike SingleCall, which is stateless.

//Creating a new instance of a remote object using new.
Employee Emp = new Employee();
//Creating a new instance of a remote object using CreateInstance.
Employee Emp = (Employee)Activator.CreateInstance(...);

Note: Above method creates an instance of the remote object based on the parameter passed. For a complete listing of the same, please refer MSDN.

//Retrieving an Existing Instance.
Employee Emp = (Employee)Activator.GetObject( typeof(Employee), HTTP://[Path]);

All the calls to the remote object (at server side) are routed through proxy object. To make things little complicated, there are two types of proxy objects involved in the process i.e. Transparent proxy and Real proxy. Transparent proxy provides the implementation of all public method to Client object which means that client object always talks to Transparent proxy which in turn makes call to Real proxy. Real proxy passes the message to channel object. Developers can customize the Real proxy to include additional functionalities if required.

Formatters

They encode and decode the message between client application and Remote object. .Net Framework provides SOAP and Binary formatter. It also supports custom formatters (IRemotingFormatter) developed by programmers.

Binary Formatter: System.Runtime.Serialization.Formatters.Binary
SOAP Formatter: System.Runtime.Serialization.Formatters.Soap

Channels

They are responsible for transmitting the message over the network. .Net Framework provides HTTPChannel and TCPChannel. It also supports custom channels (IChannel) developed by programmers.

HTTPChannel: System.Runtime.remoting.Channels.Http
TCPChannel: System.Runtime.remoting.Channels.Tcp

By default HTTP Channel uses SOAP Formatter and TCP Channel uses Binary Formatter.

Channels need to be registered with the remoting service as shown below.

//Registering a channel
ChannelServices.RegisterChannel();

Hosting a Remoting Application

Remoting Host is a runtime environment for the remote object i.e. Microsoft IIS Server.

Step By Step: Let's see the entire step once again.

1. Client object registers a channel.
2. Creation of Proxy object (Client activated or Server Activated)
3. Calling the method of remote object via proxy.
4. Client side formatter formats the message and transmits via appropriate channel.
5. Server side formatter reformats the message.
6. The specified function on remote object is executed and the result is returned.
7. Above process of formatting and reformatting is reversed and the result is returned to client object.

Above article explains the basic terms and technology involved in .Net Remoting. It's possible to create complex distributed applications using .Net Remoting. Developers can create their own custom channels and formatters depending on business needs. There is no built in security provided by .Net Remoting framework. The security features need to be provided by the hosting environment.

Reference :
http://www.c-sharpcorner.com/UploadFile/amit_agrl/DistributedComputing11232005043409AM/DistributedComputing.aspx?ArticleID=4399e73e-a059-487a-bdae-31f746ea8049

24 July, 2008

webcaste
















Polymorphism in short : Final

Polymorphism :

When the new keyword is used, the new class members are called instead of the base class members that have been replaced. Those base class members are called hidden members. Hidden class members can still be called if an instance of the derived class is cast to an instance of the base class. For example:

DerivedClass B = new DerivedClass();
B.DoWork(); // Calls the new method.

BaseClass A = (BaseClass)B;
A.DoWork(); // Calls the old method.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

In order for an instance of a derived class to completely take over a class member from a base class, the base class has to declare that member as virtual. This is accomplished by adding the virtual keyword before the return type of the member. A derived class then has the option of using the override keyword, instead of new, to replace the base class implementation with its own. For example:
public class BaseClass
{
public virtual void DoWork() { }
public virtual int WorkProperty
{
get { return 0; }
}
}
public class DerivedClass : BaseClass
{
public override void DoWork() { }
public override int WorkProperty
{
get { return 0; }
}
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Fields cannot be virtual; only methods, properties, events and indexers can be virtual. When a derived class overrides a virtual member, that member is called even when an instance of that class is being accessed as an instance of the base class. For example:

DerivedClass B = new DerivedClass();
B.DoWork(); // Calls the new method.

BaseClass A = (BaseClass)B;
A.DoWork(); // Also calls the new method.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Virtual methods and properties allow you to plan ahead for future expansion. Because a virtual member is called regardless of which type the caller is using, it gives derived classes the option to completely change the apparent behavior of the base class.

Virtual members remain virtual indefinitely, no matter how many classes have been declared between the class that originally declared the virtual member. If class A declares a virtual member, and class B derives from A, and class C derives from B, class C inherits the virtual member, and has the option to override it, regardless of whether class B declared an override for that member. For example:

public class A
{
public virtual void DoWork() { }
}
public class B : A
{
public override void DoWork() { }
}

public class C : B
{
public override void DoWork() { }
}

A derived class can stop virtual inheritance by declaring an override as sealed. This requires putting the sealed keyword before the override keyword in the class member declaration. For example:

public class C : B
{
public sealed override void DoWork() { }
}

In the previous example, the method DoWork is no longer virtual to any class derived from C. It is still virtual for instances of C, even if they are cast to type B or type A. Sealed methods can be replaced by derived classes using the new keyword, as the following example shows:
public class D : C
{
public new void DoWork() { }
}


In this case, if DoWork is called on D using a variable of type D, the new DoWork is called. If a variable of type C, B, or A is used to access an instance of D, a call to DoWork will follow the rules of virtual inheritance, routing those calls to the implementation of DoWork on class C.

A derived class that has replaced or overridden a method or property can still access the method or property on the base class using the base keyword. For example:
C#
Copy Code

public class A
{
public virtual void DoWork() { }
}
public class B : A
{
public override void DoWork() { }
}

C#
Copy Code

public class C : B
{
public override void DoWork()
{
// Call DoWork on B to get B's behavior:
base.DoWork();

// DoWork behavior specific to C goes here:
// ...
}
}


Note

It is recommended that virtual members use base to call the base class implementation of that member in their own implementation. Letting the base class behavior happen allows the derived class to concentrate on implementing behavior specific to the derived class. If the base class implementation is not called, it is up to the derived class to make their behavior compatible with the behavior of the base class.

Article taken from - Reference : http://msdn.microsoft.com/en-us/library/ms173152(VS.80).aspx

17 July, 2008

How to Share Session State Between Classic ASP and ASP.NET

How to Share Session State Between Classic ASP and ASP.NET :
http://msdn.microsoft.com/en-us/library/aa479313.aspx

Labels:

10 July, 2008

How to install or use SSL security certificate on web server Or how to use HTTPS for websites ?




  • START » RUN » MMC » OK
  • In MMC
    • File » Add/Remove Snap-In » ADD » Certificates » ADD » Computer Account
      » Next » Finish » Close » OK
    • Looks like


  • Expand Certificates (Local Computer)
  • Right-click "Personal" » ALL TASKS » IMPORT
  • Import Wizard starts
    • NEXT » BROWSE
    • Change file type to *.pfx
    • Browse to %cd-rom%\certificate\ (replacing %cd-rom% with actual CD-ROM
      drive)
    • Highligh the file "star.xyz.com_cert.pfx" » OPEN » NEXT
    • If any Password is there enter password » "Mark this key as exportable" checkbox should be
      checked » NEXT
    • NEXT » FINISH

  • If everything is done correctly, it should look like


  • Close out this MMC console session (not required to save)
  • Open up IIS Management Window

    • Expand web sites » Right-click on "Default Web Site" » PROPERTIES »
      DIRECTORY SECURITY tab
    • Click on Server Certificate button
    • NEXT » ASSIGN AN EXISTING CERTIFICATE » NEXT » HIGHLIGHT CERTIFICATE
      imported from above steps » NEXT » NEXT » FINISH
    • OK

  • Certificate is now installed

Labels: