Export (0) Print
Expand All

InvalidApplicationPathCharacters Method

IIS 7.0

Retrieves an array of characters that cannot be used in the path of an application.

Namespace:  Microsoft.Web.Administration
Assembly:  Microsoft.Web.Administration (in Microsoft.Web.Administration.dll)

public static char[] InvalidApplicationPathCharacters()

Return Value

Type: array<System..::..Char>[]()[][]
An array of characters that cannot be used in the path of an application.

In a Windows operating system that is running the common language runtime (CLR), this method will return the following characters: \?;:@&=+$,|"<>*

"*" is an invalid file system character. You cannot use the remaining characters in managed-code location tags. The "/" character is acceptable for a virtual directory.

The following example demonstrates how to use the InvalidApplicationPathCharacters method to validate application paths.

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

namespace AdministrationSnippets
    public class AdministrationApplicationCollectionInvalidApplicationPathCharacters
        // Determines if the paths provided are valid application paths
        public void ValidateApplicationPathCharacters()
            string[] paths = { "\\Blog", "/Blog", "/Blog?", ":/Blog" };
            foreach (string path in paths)
                Console.WriteLine("{0} is {1}", path, 
                    IsValidApplicationPath(path) ? "valid" : "invalid");

        // Validates applicationpath characters before adding an application
        public bool IsValidApplicationPath(string path)
            return (path.IndexOfAny(
                ApplicationCollection.InvalidApplicationPathCharacters()) == -1);

Community Additions

© 2015 Microsoft