Prajwal Kumar
Prajwal Kumar

Reputation: 177

How to host ASP.NET Core 6.0 MVC web app on IIS Express using batch script

I am new to web technologies and hosting apps. What I am currently trying is: I have created a simple app (just created a web app using Visual Studio 2022 in .NET 6.0), it automatically created the weather forecast app.

When I execute the application through VS2022, the app is hosted in IIS Express and I am able to get the response from the server. What I am actually trying is to create a batch file which has command to run IIS Express. Below is my command: (IISTest is the App Name)

start "IISTest" /MIN "C:\Program Files\IIS Express\iisexpress.exe" 
                /config:%~dp0applicationhost.config /site:"IISTest" /trace:info

I have copied the default applicationhost.config file from Documents/IIS Express/config folder and placed it along the batch file modified the <Sites> section to point it to my solution directory and updated the <bindings> to "*:44300:localhost".

With these changes when I run the command, I get the Internal Server Error.

What am I missing here? Thanks.

Upvotes: 1

Views: 2378

Answers (1)

Jason Pan
Jason Pan

Reputation: 22114

We do not recommend you to use IISExpress to start your website, because it has many limitations, such as the number of connections.

If you still want this, you can follow my steps to implement this.

1. Run the project in vs2022 and using IIS Express mode.

2. Select command line in task manager,then find the iisexpress.exe process, and copy the command line

enter image description here

enter image description here

3. we should find the applicationhost.config file under .vs folder and change the app path to the debug folder, like below

enter image description here

4. Publish the project to the folder, and compare the publish files with the debug folder files. We need to copy the web.config file from release folder to debug folder, if there is no wwwroot folder under debug folder, we also should cpoy one to here.

5. Then create a batch file.

@echo off

set iisExpressPath="C:\Program Files\IIS Express\iisexpress.exe"

echo Starting IIS Express for ASP.NET Core App...

%iisExpressPath%  /config:"F:\AspNetCore\Blazor_ApplicationRole\WebApplication1\.vs\WebApplication1\config\applicationhost.config" /site:"WebApplication1" /apppool:"WebApplication1 AppPool"

6. Then check the result

enter image description here

Upvotes: 0

Related Questions