Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to deploy a .NET Framework application to run from a network location


View products that this article applies to.

Summary

The step-by-step article describes how to deploy an application that is built on the Microsoft .NET Framework to run from a network drive.

Requirements

This article assumes that you are familiar with the following topic:
Programming by using Microsoft Visual Basic .NET
The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:
  • Microsoft Windows XP or Microsoft Windows 2000
  • Microsoft Visual Studio .NET 2003 or Microsoft Visual Studio .NET 2002

Determine the trust level

Security is an important concern when you build an application. The common language runtime grants different levels of trust to code based on specific attributes (named evidences) that the code possesses.

When the common language runtime determines that code has a specific level of trust, the common language runtime permits the code to access resources that are protected by that level of trust. By default, a .NET Framework application that runs from the Internet does not have the same level of trust as a .NET Framework application that runs from your local computer. An application that runs from your local computer can access resources such as the file system. However, an application that runs from the Internet or from a local intranet cannot access the file system on your local computer.

Typically, the default security policy is sufficient for your application. Microsoft recommends that you change this security policy only if you must. You can use the .NET Framework configuration tool (Mscorcfg.msc) to change the security policy.

In the .NET Framework, code access security controls access to resources by controlling how code runs. When a user runs an application, the common language runtime assigns the application to any one of the following five zones:
  • My Computer - The application code is hosted directly on the user's computer.
  • Local Intranet - The application code runs from a file share on the user's intranet.
  • Internet - The application code runs from the Internet.
  • Trusted Sites - The application code runs from a Web site that is defined as "Trusted" in Internet Explorer.
  • Untrusted Sites - The application code runs from a Web site that is defined as "Restricted" in Internet Explorer.
You can set the security level for each zone to High, Medium, Medium-low, or Low.

Trust levels define the resources that the application can access. The zone, together with other security evidence, such as the publisher, the strong name, the Web site, and the URL of the code, determines the permissions that the common language runtime grants to the code at run time.

Because, you cannot control the security settings on a user's computer, your application must work within the existing settings. Therefore, some resources may not be available to your application. For example, your application may have to write data to a file. However, the user's computer may raise an exception at run time to deny write access for your application.

Grant permission to the application

An application that is hosted on a network drive can run on your local computer. To run the application, you must grant a level of trust to the assembly that corresponds to the application. The trust level setting ranges from None to Full Trust. To run the application on your local computer, you must grant Full Trust permission to the assembly.

Create a console application

  1. Start Visual Studio .NET.
  2. On the File menu, point to New, and then click Project. The New Project dialog box appears.
  3. Under Project Types, click Visual Basic Projects.
  4. Under Templates, click Console Application.
  5. Click OK. By default, the ConsoleApplication1 project and the Module1.vb file are created.
  6. On the Project menu, click Add Reference.
  7. In the Add Reference dialog box, click the .NET tab.
  8. On the .NET tab, click adodb, click Select, and then click OK.
  9. Replace the existing code in the Module1.vb file with the following code.
    Module Module1
        Sub Main()
            Dim i As Integer
            Dim intMaxConnections As Integer
            Dim Conn As ADODB.Connection
            intMaxConnections = 63
            Dim IntArray(intMaxConnections) As Object
            Console.WriteLine("Starting test...")
            For i = 0 To intMaxConnections
                Conn = CreateObject("ADODB.Connection")
                Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" _
                  & "Data Source=C:\Program Files\Microsoft " _
                  & "Office\Office10\Samples\Northwind.mdb;"
                Conn.Open()
                Console.WriteLine("Open connection is " & i)
                IntArray(i) = Conn
            Next
        End Sub
    End Module
    
  10. On the Build menu, click Build Solution.
  11. Quit Visual Studio .NET.

Map the network drive and deploy the compiled application

  1. Do the following, depending on your operating system:
    • On Windows XP, click Start, point to All Programs, point to Accessories, and then click Windows Explorer.
    • On Windows 2000, click Start, point to Programs, point to Accessories, and then click Windows Explorer.
    The My Documents window appears.
  2. On the Tools menu, click Map Network Drive. The Map Network Drive dialog box appears.
  3. In the Drive box, select any disk drive other than your local disk drives. For example, select any disk drive between D and Z.
  4. Click Browse. The Browse For Folder dialog box appears.
  5. Locate and then click the folder that you want to map as a network drive, and then click OK.

    Note To make sure that this step works correctly, share the network folder that you want to map as a network drive.
  6. In the Map Network Drive dialog box, click Finish.
  7. In Windows Explorer, copy the executable file that you created in the "Create a console application" section from the Bin folder in your console application folder to the mapped network drive.

Assign Full Trust permission

  1. Do the following, depending on your operating system:
    • On Windows XP, click Start, and then click Control Panel.
    • On Windows 2000, click Start, point to Settings, and then click Control Panel.
  2. Do the following, depending on the version of the .NET Framework that you are using:
    • If you are using the .NET Framework 1.1, double-click Administrative Tools, and then double-click Microsoft .NET Framework 1.1 Wizards.
    • If you are using the .NET Framework 1.0, double-click Administrative Tools, and then double-click Microsoft .NET Framework Wizards.
    The .NET Wizards window appears.
  3. In the .NET Wizards window, click Trust an Assembly. The Trust an Assembly dialog box appears.
  4. Click to select the Make changes to this computer option, and then click Next.
  5. Click Browse. The Choose Assembly dialog box appears.
  6. In the Choose Assembly dialog box, locate the executable file on the mapped network drive, and then click Open.
  7. In the Trust an Assembly dialog box, click Next.
  8. In the Trust an Assembly dialog box, move the slider to Full Trust, and then click Next.
  9. Click Finish.
  10. To run the executable file from the mapped network drive, double-click the file in Windows Explorer.

↑ Back to the top


References

For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
300856 How to connect to shared folders over the network (on a domain) in Windows 2000
For more information about the security aspects of running an assembly from a network drive, visit the following Microsoft Developer Network (MSDN) Web sites:

↑ Back to the top


Keywords: kbnetwork, kbdeployment, kbappdev, kbdev, kbhowtomaster, KB832742

↑ Back to the top

Article Info
Article ID : 832742
Revision : 3
Created on : 11/29/2007
Published on : 11/29/2007
Exists online : False
Views : 474