Set Mimetypes per IIS site

Efff dd 576 Reputation points
2023-04-12T22:46:33.9466667+00:00

how to apply a mimetype to one site under DSC.?

@{
            ShortName          = 'example'
            DNSSuffix          = 'abc.com'
            SiteAuthors        = ('ExampleUser')
            State              = "Started"
            Certificate        = "fasdfsfdsfdfd7E86dsfsdfdsfd"
            RuntimeVersion     = '' # 'v2.0' or 'v4.0'
            Enable32Bit        = '' # 'Enabled' or 'Disabled'
            HSTS               = 'Present'
            HSTSAge            =  '31536000' #52 Weeks
            IISAnonymousAuth   = '' # 'Enabled' or 'Disabled'
            IISAnonymousUser   = '' # '' for AppPool Identity or 'IUSR' for IUSR account
            IISWindowsAuth     = '' # 'Enabled' or 'Disabled'
            Nodes              = ('') #Empty List
            Applications       = @()
            VirtualDirectories = @()
        } #example
    )
}

Windows development | Internet Information Services
Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Yurong Dai-MSFT 2,846 Reputation points Microsoft External Staff
    2023-04-13T06:23:12.3766667+00:00

    Hi @Efff dd,

    The following code is an example of a DSC configuration script, which contains the property definition of the website, you can refer to it:

    Configuration WebsiteConfig
    {
        Import-DscResource -ModuleName PSDesiredStateConfiguration
    
        Node localhost
        {
            WindowsFeature IIS
            {
                Ensure = "Present"
                Name   = "Web-Server"
            }
    
            WindowsFeature ASPNET45
            {
                Ensure = "Present"
                Name   = "Web-Asp-Net45"
            }
    
            xWebsite Site
            {
                Ensure          = "Present"
                Name            = "example"
                State           = "Started"
                PhysicalPath    = "C:\inetpub\wwwroot\example"
                BindingInfo     = MSFT_xWebBindingInformation
                {
                    Protocol    = "http"
                    Port        = "80"
                    IPAddress   = "*"
                    HostName    = "example.abc.com"
                }
                MimeMap         = @(
                    @{
                        Extension  = ".htm"
                        MimeType   = "text/html"
                    },
                    @{
                        Extension  = ".xml"
                        MimeType   = "text/xml"
                    }
                )
                ApplicationPool = "exampleAppPool"
            }
    
            xWebAppPool exampleAppPool
            {
                Ensure          = "Present"
                Name            = "exampleAppPool"
                ManagedRuntimeVersion = "v4.0"
                ManagedPipelineMode   = "Integrated"
            }
        }
    }
    
    WebsiteConfig -OutputPath "C:\DSC\Configs"
    
    

    This code defines a website named "example", uses the application pool "exampleAppPool", and adds two MIME type mappings here.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the email notification for this thread. Best regards, Yurong Dai

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.