# Hosting Umbraco in IIS

## Configuring IIS for .NET

* Install the [.NET Core Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/) and download the [**Hosting Bundle**](https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/hosting-bundle?view=aspnetcore-8.0). Ensure you download the correct .NET version as per the [Requirements](/umbraco-cms/13.latest/fundamentals/setup/requirements.md) article.
* Restart IIS (`net stop was /y` followed by `net start w3svc`)
* Create a site in IIS and ensure that the .NET Common Language Runtime (CLR) version is set to `No Managed Code` for the Application Pool.

![IIS Application Pool](/files/7gYyhocadRzQWE1HsaTp)

### Publish website for manual deployment to IIS

You can use the dotnet CLI to compile and collate all files required for hosting

```
dotnet publish -o ../deployment-artefacts -f net7.0
```

Alternatively, you can use the File Transfer Protocol (FTP) publishing in Visual Studio to compile and collate all the required files for the application to run.

In Visual Studio, select the Umbraco web project in the *Solution Explorer* and choose the *Publish...* command.

![Publish...](/files/TX3rHq28Y5v7MFCJ17pj)

{% hint style="info" %}
**Deploy a website for automated deployment with Azure DevOps to IIS**

You can use the [IIS Release task in Azure DevOps](https://learn.microsoft.com/en-us/azure/devops/pipelines/release/deploy-webdeploy-iis-deploygroups) to deploy your website to your Web Server. This task is a wrapper for `MSDeploy.exe` and can be configured as preferred.
{% endhint %}

### Environment Variables in ApplicationHost.config

In the *Management* section you find the *Configuration Editor*:

![IIS Website Configuration](/files/4tCB7CbaaNkV42WeKW9G)

One section is of particular interest:

* In the first, left hand dropdown list (*Section:*) choose: `system.webServer/aspNetCore` section.
* In the second, right hand dropdown list (*From:*) choose: `ApplicationHost.config <location path='[YOUR-SITENAME]'>`. This ensures your settings will be stored in a machine specific file. The configuration files might end in a public repository and should not contain sensitive data like Connection Strings or Simple Mail Transfer Protocol (SMTP) configuration with username and password. Additionally, by default the configuration file will be overwritten during each publish processes.

![IIS Configuration Editor](/files/dGf1HMlH1ZoOOcYxglrM)

Find the line named *environmentVariables* and open the dialog to add environment variables. These work similar to the *launchSettings*. You can define `ASPNETCORE_ENVIRONMENT` and create an `appSettings.[ASPNETCORE_ENVIRONMENT].json` file. Or even better create environment variables for sensitive settings like passwords. There are some differences to `launchSettings.json` configuration:

* Variable names need to change the object structure form JSON by combining the segments with double underscore `__` e.g. `ConnectionStrings__umbracoDbDSN`
* Escaped backslashes `\\` e.g. `serverName\\databaseInstanceName` are replaced by single backslash `\` e.g. `DATABASESERVER123\SQL2017`

### IIS Hosting models

IIS can host .NET applications using 2 different hosting models

* [In-process (default)](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/in-process-hosting?view=aspnetcore-7.0)
* In-process hosting runs a .NET app in the same process as its IIS worker process
* [Out-of-process](https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/out-of-process-hosting?view=aspnetcore-7.0) - to enable this model you need to edit your .csproj file and add:

```js
<PropertyGroup>
  <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
```

Out-of-process .NET apps run separately from the IIS worker process. The module controls the management of the Kestrel server and requests are proxied between them.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.umbraco.com/umbraco-cms/13.latest/fundamentals/setup/server-setup/iis.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
