Web.config setup for IIS development - iis

I am running an IIS instance (Not the default IIS Express) on which I have configured my ASP.NET Core 3.1 MVC project.
I would like to configure my web.config file, so that I have the following behavior:
Each time i update a view (.cshtml file) in my solution, the update is instantly visible after i refresh the page.
Each time i update a controller or a model (.cs file) the update becomes visible after a rebuild of the solution.
What I currently have is the following configuration in my root directory:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\bin\Debug\netcoreapp3.1\Live.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
Now with the following configuration I have to rebuild each time I want to see the result of my modifications. There's also another problem, each time I rebuild the app I encounter the following problem:
1>D:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4502,5): error MSB3021: Unable to copy file "obj\Debug\netcoreapp3.1\Live.dll" to "bin\Debug\netcoreapp3.1\Live.dll". The process cannot access the file 'bin\Debug\netcoreapp3.1\Live.dll' because it is being used by another process.
I have to manually stop the IIS instance and then rebuild my solution.
I have worked on a project where this was the way things were done, however I never figured out how it was configured. I would appreciate any help if possible, Thanks.

Related

.NET Core WebAPI IIS Deploying

I have created a webAPI using .Net Core and trying to publish it to IIS. But getting HTTP 500.19.
It's looking for web.config file but I don't have it.
What should I do?
Did you installed this: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?tabs=aspnetcore2x&view=aspnetcore-3.1
If Yes check your permissions on the folder. The identity under which your web application runs in IIS may has not full access to the folder in which the web.config file is found. You could change your identity under the appPool or grant access to your folder. If you deployed into the wwwroot folder the IUser should have access to the folder.
When you publish your .net core in IIS please remember to install .net core web hosting bundle because it is not supported by default. IIS handle request based on different handlers. Even when you install the extension, aspnet core module is not registered. So please remember to set
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<aspNetCore processPath=".\myapp.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>
If the solution doesn't fix this. Then something in your web.config is corrupting the application. Please post a screenshot the detailed error message. Then we would know how to fix this completely.

Can't publish ASP.NET Core anything to IIS Host

First I will like to disclose that this is my first attempt at publishing a .net core app to a live server. Everything I have done on the past has been on a local Host Server.
The problem I am having is that I can't get any kind of application even the temple created in VS2017 V15.7.2 to return anything other than 500 server error. I can't even get it to produce log files so I can try to figure out what is going on.
Here is my web.config file from the published server.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\BareBones.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
I can connect via FTP and see all of the files but, that is about it. Of course everything works great locally.
Any and all help is greatly appreciated.

Edit Web.config file

I have the following webconfig file produced by visual studio 2017 on a .net core application
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\SportsStore.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 5795049b-4d7e-4559-9010-f9134df11849-->
Although the publish succeed I get the following on the web page
Detailed Error Information:
Module
IIS Web Core
Notification
BeginRequest
Handler
Not yet determined
Error Code
0x8007000d
Config Error
Config File
\\?\C:\inetpub\wwwroot\sportstore\web.config
Requested URL
http://localhost:80/sportstore
Physical Path
C:\inetpub\wwwroot\sportstore
Logon Method
Not yet determined
Logon User
Not yet determined
Config Source:
-1:
0:
Because I have already work only on apache and the build in IIS express of visual studio I do not know where to start from. Internet has plethora of info and I tried many things but nothing.
Any suggestion?

HTTP Error 502.5 running ASP.NET Core 2.0 app from IIS

I'm getting an HTTP 502.5 error when trying to run my ASP.NET core 2.0 web app from IIS.
I've installed the .NET Core Windows Server Hosting Bundle and checked all my IIS settings as per this document https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?tabs=aspnetcore2x
The web.config looks like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\OscarWeb.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
The Windows event log produces the following errors.
It is IIS v6.2 running on Windows Server 2012 R2. The web application was built using ASP.NET Core 2.0.
When I run dotnet from the commandline as follows there are no errors:
dotnet oscarweb.dll
The first thing you have to do in this scenario is to create the logs folder if it is missing and check the stdout logs generated.
It can be several different things but from personal experience the most common issue i had was IIS not having enough permissions to run it. In IIS you can configure the Identity used in Advanced Settings. If it is using ApplicationPoolIdentity then change it to LocalSystem and see if it works. The logs in the stdtout file however will give you the answer.
The solution to this problem (in my case at least) was to reboot the web server. After installing the .NET Core Windows Server Hosting Bundle you need to reboot the server for them to be registered correctly.
Thanks to Chris Pratt (first comment underneath my question) for suggesting the answer :)
Not sure if your webconfig is complete. I believe aspnetcore tag needs to have the ASPNETCORE_ENVIRONMENT environment variable set as well.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\OscarWeb.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="YourRuntimeEnv" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>

Unable to open ASP.NET Core website's Module in IIS

I've deployed ASP.NET Core 1.1.1 app in IIS-10 on Windows 10 following this tutorial. But when I try to open Modules in IIS, I get the following error [For clear view you can click on the image to zoom in]:
Note:
It's a development machine and already has installed as shown below:
The app pool for the app is as follows:
And the Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
UPDATE: Issue may have been related to this post
It turns out that ASP.NET Core Module is installed separately from the SDK and I needed to install ASP.NET Core Module for the above issue to be resolved as explained in this post. Thanks to #natemcmaster for helping me resolve the issue.

Resources