- You have set up your dev environment with Grafana, see here.
- You have a Windows Server with IIS
A detailled documentation to host .NET Core on IIS can be found here.
- Create a App Pool in IIS and give it a name, for example ".NET Core"
- Set ".NET CLR version" to "No managed code"
- Go to "Advanced options..." and set "Start Mode" to "AlwaysRunning", so the background polling hosted services will continue running and not getting killed after a few minutes.
- Create a web site and assign the App Pool just created
- Configure the Environment Variable for selecting the
appsettings.Production.json
by doing the following steps:- Go to your application in IIS and choose Configuration Editor.
- Select Configuration Editor
- Choose system.webServer/aspNetCore in "Section" combobox
- Choose Applicationhost.config ... in "From" combobox.
- Click on enviromentVariables element and open edit window.
- Add environment variable named "ASPNETCORE_ENVIRONMENT" with content "Production"
- Close the window and click Apply.
To set up the SQL Express database on the server, follow these steps:
- Install SQL Server Express 2017 (or newer) on the server. Client Tools are not necessary.
- Configure the Windows Firewall to allow TCP port 1433 on the local machine
- Configure the SQL Server to enable TCP and on port 1433 via SQL Server Configuration Manager
- Check the Windows username of the App Pool. Remember how you named your App Pool Identity before. The App Pool name ".NET Core" for example will result in a Windows User named "IIS APPPOOL.NET Core".
- Configure the permissions with sqlcmd.exe (run
cmd
and start it withsqlcmd -S .\SQLEXPRESS
) and run these SQL commands:
' Only for the first time, if the database does not exist yet
CREATE DATABASE [GraphIoT]
GO
USE [GraphIoT]
GO
CREATE LOGIN [IIS APPPOOL\.NET Core] FROM WINDOWS;
GO
CREATE USER DotNetCore FOR LOGIN [IIS APPPOOL\.NET Core];
GO
GRANT ALL PRIVILEGES TO DotNetCore;
GO
sp_addrolemember @rolename = 'db_datareader', @membername = 'DotNetCore';
GO
sp_addrolemember @rolename = 'db_datawriter', @membername = 'DotNetCore';
GO
sp_addrolemember @rolename = 'db_owner', @membername = 'DotNetCore';
GO
In your dev environment go to the main application folder src/GraphIoT.App/
and copy appsettings.Development.json
and name it appsettings.Production.json
All credentials should stay the same for development and production, but you may want to set your logging level to only warning:
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
},
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
And set your connection string to the SQL Server Express database instance you just created, with Windows integrated security authentication:
"ConnectionStrings": {
"SmarthomeDB": "Data Source=.\\SQLEXPRESS;Database=GraphIoT;Trusted_Connection=Yes;"
}
Go to the grafana prod config folder src/GraphIoT.Grafana/Grafana/conf/production/
and copy custom.template.ini
and name it custom.ini
Edit this newly created custom.ini
and enter your external URL:
# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = https://your.domain/path-to-graphiot-website/grafana
- Go to the publish profiles folder
src/GraphIoT.App/Properties/PublishProfiles/
and copyCustomProfile.template.pubxml
and name itCustomProfile.pubxml
- In Visual Studio, right click on the main "GraphIoT.App" project in folder "MainWebserver" and select "Publish..."
- Edit the "Custom Profile" and enter your server, web site name and credentials for WebDeploy
- Hit "Publish"
Check if the application runs and is reachable. The database tables will be created automatically on first run.
Setup your grafana admin user, JSON datasource and dashboards.
You have set up and deployed the application!