VirtualDirectoryDefaults.UserName Property

Definition

Gets or sets the user name that is used by default for all virtual directories under the current context.

public:
 property System::String ^ UserName { System::String ^ get(); void set(System::String ^ value); };
public string UserName { get; set; }
member this.UserName : string with get, set
Public Property UserName As String

Property Value

The default user name that a virtual directory uses to access its physical location.

Examples

The following example creates a new application that has explicitly set virtual directory defaults and then creates two new virtual directories. The virtual directory defaults are applied to the newly created directories when you update the configuration system by calling the CommitChanges method.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    public class AdministrationApplicationVirtualDirectoryDefaults
    {

// Creates a new application, sets the virtual directory  
// defaults, creates two new virtual directories, and then  
// displays the new virtual directory values.
public void SetVirtualDirectoryDefaults()
{
    ServerManager manager = new ServerManager();
    Site defaultSite = manager.Sites["Default Web Site"];

    // Set up the defaults for the default application of the 
    // default Web site.
    Application app = defaultSite.Applications.Add(
        "/JohnDoe", @"C:\inetpub\wwwroot\john");

    app.VirtualDirectoryDefaults.LogonMethod = 
        AuthenticationLogonMethod.ClearText;
    app.VirtualDirectoryDefaults.UserName = @"NorthWest\JohnDoe";
    app.VirtualDirectoryDefaults.Password = @"kB56^j83!T";

    // Add two virtual directories.
    app.VirtualDirectories.Add(
        "/blogs" , @"\\FileServer\c$\blog_content\");
    app.VirtualDirectories.Add(
        "/photos", @"\\FileServer\c$\photo_content\");
    manager.CommitChanges();

    // Read the updated configuration.
    app = defaultSite.Applications["/JohnDoe"];

    foreach (VirtualDirectory vdir in app.VirtualDirectories)
    {
        Console.WriteLine("Virtual Directory Found: {0}", vdir.Path);
        Console.WriteLine("  |-Logon Method : {0}", vdir.LogonMethod);
        Console.WriteLine("  |-Username     : {0}", vdir.UserName);
        Console.WriteLine("  +-Password     : {0}", vdir.Password);
    }
}
    }
}

Remarks

You should use this property when the virtual directory requires alternative credentials to access secured content, such as a UNC path. The value set on this property is used by default for all virtual directories in the current context when a user name is not explicitly set.

Applies to