Tuesday, May 18, 2010

ClickOnce

Advantage of using ClickOnce

1. windows installer deployment requires administrator privileges where is normal user can do installation using ClickOnce
2. ClickOnce allow to set automatic application updates
3. There will not be any version conflicts using ClickOnce



Requirement: Need to deploy a console based application to all the machines in the network. And whenever there is any functionality addition to application it should update in already installed the applications in the network.














Solution: Use ClickOnce feature provided by Microsoft along with visual studio 2005.

People were not preferred to develop any winforms/console applications before introduction of ClickOnce feature. This is because deployment & maintenance was an overhead.

ClickOnce helps you to deploy your WPF, winforms or console application in any machines in the network or any standalone machines. There are 3 ways in which we can achieve this.

  1. Publish using http
  2. Copy to shared folder in server.
  3. Write to CD/DVD
Here are the steps for Publish using http.

Make your changes in the application and set assembly version in assemblyInfo.cs file




You could also check assembly version at Project-Properties-Publish tab- Modify publish version



Use publish option under build menu for publishing the changes using http




 
Click on Next





Click on Finish, Brower opens up with the publish details. Choose Install button to install the software










Now big question: Say I am a user in the network and I have already installed the application. So whenever a new patch is updated or new functionality is added, I want those changes to reflect in my application automatically.


ClickOnce give an option to configure this. It is called as Update Strategy. This can be achieved in 3 ways:

  1. After starting up the application
  2. Before starting up the application
  3. making the updates required

I am going with before starting up the application. This option can be set using Project-Properties-Publish tab-Click on Update button.






Say I have updated my application or I did some code change, I am going to publish it in to the website





Repeat the publish steps.





You get the updates when you click on Ok



 
How it works: I guess it is based on publisher-Subscriber policy.

.net difference between throw and throw ex

  • stack information is truncated if we are using throw ex
  • where as stack information gets preserved in throw

throw ex - throw
throw  - rethrow


class Program
    {
        static void Main(string[] args)
        {
            A aa = new A();
            aa.Method1();
        
            Console.Read();
        }
    }

    class A
    {
        public void Method1()
        {
            try
            {
                B bb = new B();
                bb.Method2();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.StackTrace);
            }
        }
    }

    class B
    {
        public void Method2()
        {
            try
            {
                C cc = new C();
                cc.Method3();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

    class C
    {
        public void Method3()
        {
            try
            {
                throw new InvalidOperationException();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            
        }
    }
 


throw
at CatchSample.C.Method3() in C:\temp\oops\oops\CatchSample\Program.cs:line 60
at CatchSample.B.Method2() in C:\temp\oops\oops\CatchSample\Program.cs:line 45
at CatchSample.A.Method1() in C:\temp\oops\oops\CatchSample\Program.cs:line 25

throw ex
at CatchSample.B.Method2() in C:\temp\oops\oops\CatchSample\Program.cs:line 45
at CatchSample.A.Method1() in C:\temp\oops\oops\CatchSample\Program.cs:line 25

NoteStackTrace information is lost in case of throw ex


Reference:

http://aspadvice.com/blogs/joteke/archive/2004/04/15/2277.aspx

http://geekswithblogs.net/sdorman/archive/2007/08/20/Difference-between-quotthrowquot-and-quotthrow-exquot-in-.NET.aspx

Monday, May 17, 2010

Accessing COM object from .net

  • .NET COM interop allows to use existing COM object in .net without modifying original component
  • First step is to import relevant COM types using COM interop utility.
  • Tlbimp.exe is the utility to import COM types to managed application.
  •  

Reference: http://msdn.microsoft.com/en-us/library/aa645736%28VS.71%29.aspx

Saturday, May 15, 2010

Difference between singleton and static classes

  • Singleton can be used with parameters to methods, but you cannot use static class as parameters.
  • Singleton can be used with interfaces
  • static class mainly use to hold gloabl data of application

Reference: http://dotnetperls.com/singleton-static

Saturday, May 1, 2010

Security in ASP.NET

Following are the steps in which security can be enforced in ASP.NET

  1. Authentication
  2. Authorization
  3. Privacy or Confidentiality
  4. Data integrity
  5. Non-Repudation

Authentication is the process of validating the user credentials.
Authorization is the process of checking the access of the authenticated user for a resource.
Privacy is the process of ensuring the passed message over wire is not dropped
Data integrity is the process of ensuring the data is not hampered or modified while passing through the wire.
Non-repudiation ensures that the author of the message/data cannot disavow responsibility.


Authorization is the process of checking access of an identity. .NET allows 2 ways to authorize access to the resource.

  1. FileAuthorization
  2. URLAuthorization
FileAuthorization check access in access control list (ACL) of the ASP.NET page for the identity. ACL will have the access details for the users, and authorization happens by looking at ACL.

URLAuthentication allow or deny access to user or role based on the entry in the configuration file. Authorization section in the configuration file allow to add access detail for the user.


  
  
  
  




Reference:

http://www.c-sharpcorner.com/UploadFile/gsparamasivam/CryptEncryption11282005061028AM/CryptEncryption.aspx