Deploying Applications Effortlessly Using Zero-Install Application Deployment


Deploying Applications Effortlessly Using Zero-Install Application Deployment

One of the new capabilities introduced by the .NET Framework to ease the deployment of assemblies (assemblies can be graphical applications and/or just a set of components) is the notion of having a zero-install mechanism for deploying them to users' desktops. For instance, consider a simple GUI application (code shown in Listing 14.1). Once compiled, the application can be executed by running "HelloApp.exe " on the local machine. To run this application on another computer (which has the .NET Framework 1.1 Redistributable), simply copy the executable and any other DLLs associated with it into a directory on the new workstation, and you should be able to run it without registering any components .

Whereas this deployment mechanism, popularly known as XCOPY deployment, is useful because it simplifies deployment, it still involves installation or copying of the application file onto a user desktop. Next time, when the application is updated to another version, a similar process will be required again. To eliminate this repeated update and in some sense get the benefits of the Web-based application delivery model to desktop/rich client applications, .NET Framework provides the notion of a Downloadable Application that can be installed and executed locally directly from a remote Web site. So for instance, you could copy the executable and the associated DLLs into a Web server root (for instance C:\inetpub\ wwwroot \SmartApps directory) and make them available from the Web. To use the applications, the user simply has to browse to http://localhost/SmartApps/HelloApp.exe (or a similar URL) and execute the application. Next time there is an update, the user can simply click or browse to the URL and the updated version of the application will be downloaded and executed.

Listing 14.1 A Simple Zero-Install .NET Application
 using System; using System.IO; using System.Windows.Forms; namespace HelloApp {    public class HelloApp : Form    {       private Button WriteButton;       private TextBox MsgBox;       public HelloApp()       {          WriteButton = new Button();          MsgBox = new TextBox();          WriteButton.Dock = DockStyle.Bottom;          WriteButton.Text = "Write To File";          MsgBox.Dock = DockStyle.Fill;          MsgBox.Multiline = true;          MsgBox.Text = "Enter Text....";          Controls.Add(MsgBox);          Controls.Add(WriteButton);          Text = "Hello App";       }       public static void Main()       {          Application.Run(new HelloApp());       }    } } 

So far, your application didn't do much on the client workstation. For instance, a key advantage of a rich client application is the added benefit that it can utilize local resources such as read/write local files. To do that, you add an event handler to the Write button of the preceding application (Listing 14.2), which takes the text entered into the text box and writes it to a local file C:\HelloApp.txt. Assuming that you do have a C: drive on your machine to which your user account has access, after this application is executed locally (from a directory such as C:\HelloApp\HelloApp.exe), it runs fine and is able to write into the directory.

Listing 14.2 Writing into Files from Downloadable Applications
 using System; using System.IO; using System.Windows.Forms; namespace HelloApp {    public class HelloApp : Form    {       private Button WriteButton;       private TextBox MsgBox;       public HelloApp()       {          WriteButton = new Button();          MsgBox = new TextBox();          WriteButton.Dock = DockStyle.Bottom;          WriteButton.Text = "Write To File";  WriteButton.Click += new EventHandler(this.WriteToFileButton_Click);  MsgBox.Dock = DockStyle.Fill;          MsgBox.Multiline = true;          MsgBox.Text = "Enter Text....";          Controls.Add(MsgBox);          Controls.Add(WriteButton);          Text = "Hello App";       }       public static void Main()       {          Application.Run(new HelloApp());       }  private void WriteToFileButton_Click(object sender, System.EventArgs e)   {   String filename = "c:\HelloApp.txt";   String text = MsgBox.Text;   StreamWriter sw = new StreamWriter(filename);   sw.WriteLine(text);   sw.Close();   }  } } 

Now, modify and compile the application and update the executable on the remote site ( http://localhost/SmartApps/HelloApp.exe ). When you run the application again, try writing some text into the text box, and click the Write button. You will get a message that indicates that a security exception was thrown while the application was run (shown in Figure 14.1).

Figure 14.1. Security exception thrown by HelloApp zero-install application while attempting to write to a file.

What went wrong? Well, nothing went wrong. If you think about it carefully , the exception was good. The application, which was remotely downloaded and executed, tried to access local system protected resources. Because this application wasn't explicitly marked fully-trusted, the CLR-based execution model flagged the execution of the file writing code as unsafe and threw an exception to signal that. This is really the heart of the Code Access Security (CAS) model introduced with the .NET Framework.



Microsoft.Net Kick Start
Microsoft .NET Kick Start
ISBN: 0672325748
EAN: 2147483647
Year: 2003
Pages: 195
Authors: Hitesh Seth

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net