Make .Net Core Web API deployed on IIS to work with Port 80 - asp.net-core-webapi

I created a Web API in using .Net Core 3.1 using VS 2022
Nothing fancy this is just the bare bones API that we get using the template with the Weather controller to which I added Swagger.
Everything works fine from VS -> IIS Express.
Tried deploying to IIS locally on my development system.
Did not work.
First is the forbidden page when browsing from IIS:
And then tried accessing swagger:
Publish Settings from VS
In IIS:
Did not change the defaults in Manage Application they are set to port 80 for Http and 443 to Https.
Out of curiosity I ran the executable from the publish folder, took the URL from there. This worked and the swagger page is displayed.
So either it's the port or something else that I am not able to figure out.
Appreciate any clues and guidance to make this work.
Thanks in advance.

Below are the steps to publish the asp.net core web API on IIS server:
Open a project in visual studio, right-click on it and choose publish option
Choose the folder option and select a target folder and publish it
Open the IIS server, right-click on the server name, and select add website
Enter website name, select path, and enter a port number -> click ok
Open application pools, double click on you web API application pool name
From the .net CLR version select no managed code
Install asp.net core hosting bundle
Add the below code in the Program.cs file:
if (app.Environment.IsDevelopment()|| app.Environment.IsProduction())

Related

How to publish ASP.NET Core 5 Web Site to IIS?

I installed Visual Studio 2015 RC and created the sample Web Site project.
I published it in Visual Studio using its publishing tool to file system. The output is:
I tried to target IIS both this folder and wwwroot folder but nothing changed. I always receive an Access is Denied error.
Checked the permissions. They are OK. I'm always able to run my other web sites...
I want to publish it targeting clrcore. But I already tried to publish it using clr and failed there too. It is the same error.
How is the publishing process should be when I want to run a coreclr website in IIS? And I don't even know if it is possible to serve a coreclr project on IIS.
By the way there is nothing about .NET Core in application pools dialog in IIS. So I don't know what could my poor IIS do here.
There are full instructions from MS:
http://docs.asp.net/en/latest/publishing/iis.html
TL;DR
You need to install HTTP platform Handler. Other than that, if you could get a standard MVC 5 app to work, you should be ok. The only change I needed to make was installing the plstform handler.
Of Course, In VS I publised to a folder, then copied the contents to the Web server. The root folder to the site must point to the wwwroot and the approot will be at the same level.
As far as I know, You can't host ASP.NET Core 5 Web Site on IIS, it works with self hosting only.

Migrate a ASP.Net application from one server to another server

I have developed a ASP.Net MVC 4 application with Visual Web Developer Express 2010. It was successfully published/deployed to a remote server A (development server) using the Web Developer's built-in publishing tool and it works perfectly on it IIS 7.0 with the web deployment component.
Now I want to deploy it to another remote server B (production server). This one sits in an isolated environment and does not have Internet access! Even if server B is a replica of server A, its IIS 7.0 does not have the web deployment tool component installed. So the built-in publishing tool does not work for the web deployment option.
I then tried to publish it using the File System option. I copied the exported files to a new folder on IIS on server B. The folder was configured the same way as its counterpart on server A. I tried the URL on server B and it just gave me directory/files listing on the browser instead of the welcome page of the application.
Has anybody got the experience or tips to solve the issue? Thanks.
Cheers,
Alex
edit:
because it a MVC site, the default document doesn't apply. check the following steps:
IIS Extension Less URLs are enabled and allowed.
ASP.NET 4.0 is installed and registered. C:\Windows\Microsoft.NET\Framework\<version> and then aspnet_regiis -i (this will typically force IIS to use the MVC infrastructure instead of using the default document methodology)
Ensure App Pool is in 4.0 Integrated mode.
Ensue that the IIS Advanced Settings for the website are showing the right root folder path.

Can't start ANY ASP.NET projects

I've been trying to fix this for quite some time now, but I simply can't make any ASP.NET projects in Visual Studio Express 2012 for Web. I get this error when I start a new project:
Web application projects are currently configured to use IIS Express. To switch back to using the Visual Studio Development Server, change the development server option under the Projects and Solutions/Web Projects Category of the Options menu. Configured IIS Express failed with the following error:
Filename: redirect.config
Error: Cannot read Configuration file.
So I went on the internet to try and find others with the same error but I can't find a concrete solution to my problem. I find something similar for older versions, but it doesn't fix my problem. I do have the IIS Manager up under my Services (When you want to Manage Windows). I even made a virtual folder, but to no avail. Still doesn't work.
I want to use IIS
How do I fix this?
In Solution Explorer, right-click the name of the Web application project for which you want to specify a Web server, and then click Properties
In the Properties window, click the Web tab.
To choose the Visual Studio Development Server, under Servers, click Use Visual Studio Development Server.
To use a specific port number with the Visual Studio Development Server, select Specific port and enter the port number. By default, the Auto-assign Port option is selected, and the port number that has been assigned to your application appears
To choose IIS, under Servers, select Local IIS Web server. This option is not available if IIS is not enabled on your computer. A URL that combines localhost with the name of your Web application will automatically be created for you and appear in the Project URL box (for example, l ocalhost/WebApplication1).
To choose IIS, under Servers, select Local IIS Web server. This option is not available if IIS is not enabled on your computer. A URL that combines localhost with the name of your Web application will automatically be created for you and appear in the Project URL box (for example, loca lhost/WebApplication1).
To choose a custom Web server, select Use Custom Web Server. In the Server URL box, type the URL that Visual Studio should start when it runs the current project.
You may for example open you project file in notepad search for the string <useiisexpress>true</useiisexpress> replace it with the string <UseIIS>True</UseIIS> save and reload the project.
Make a copy of the project file first though.

How do I deploy MVC3 Hello World App to localhost and configure IIS

I am having some trouble deploying my MVC3 application to my localhost. I am looking for details to build and deploy a ASP MVC 3 application to my local system. I've tried to deploy this, but have run into problem after problem. Instead of tracking each problem down separately (and I may have to do this anyways) I would like to create a one stop guide for myself and others that see this post.
I'm looking for steps including libraries to install (ASP MVC3, IIS, etc) on a Win7 SP1 machine with VS2010 installed. Also how do I set up IIS, and how do I publish? The goal will be to deploy this web app to another Win7 machine in the house, but localhost will be the first step. In addition, it would be helpful to know whatever steps are necessary to make the website accessible from another machine on the same network.
Here is what I have done so far:
Created an ASP MVC 3 application with VS2010
Built and Run
Installed IIS
In IIS - "Added Application" on "Default Web Site" with the Alias: "Hello"
4a. "Hello" runs on the DefaultAppPool, .Net 4.0; Integrated Pipeline
4b. "Hello" has the physical path C:\inetpub\Hello
In VS2010 - right clicked the project and selected "Publish", using FTP
web browser: navigate to "localhost/Hello"
500.19 - Internal Server error:
Config Error: This configuration section cannot be used at this path. This happens when
the section is locked at a parent level. Locking is either by default
(overrideModeDefault="Deny"), or set explicitly by a location tag with
overrideMode="Deny" or the legacy allowOverride="false"
Config File:
\\?\C:\inetpub\wwwroot\web.config
Requested URL:
http://localhost:80/Hello
Physical Path:
C:\inetpub\Hello
Config Source:
68: <validation validateIntegratedModeConfiguration="false" />
69: <modules runAllManagedModulesForAllRequests="true" />
70: </system.webServer>
Download and install ASP MVC 3
Create an MVC3 Hello World App in Visual Studio
Install IIS from the “Windows Features” / “Turn Windows features on or off” in Windows.
Next, you need to configure a website in IIS. I created one on port 81. Open IIS Manager, and “Add a Website” to the “Sites” node.
For this website, I created this on D:\WebSite, and configured it to run on DefaultAppPool, configured for .NET 4.0, on port 81.
Most of the time, IIS is installed after installing the .NET Framework, so you’ll need to run some commands to register ASP.NET on IIS.
start cmd.exe as an administrator and run aspnet_regiis -i in C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Initially, I had some trouble publishing the project to the destination but for whatever reason, Publish method: “FTP” to Target Location “D:\WebSite” seems to work quite well and publish only the minimum required files.
traditionally you could only deploy to your server using ftp. Though it doesn't make a lot of sense to ftp to a server which runs locally. However Microsoft recently introduce the Web Deployment Tool which works really well. Once you install them then you have the option of creating a deployable package
In Publish dialog, choose option Filesystem instead of FTP, and give it path you have set in IIS

Publish ASP.NET MVC 3 (Razor) app onto remote server running Windows Server 2003 with IIS 6

I have built an ASP.NET MVC 3 web application (with exlusively Razor/cshtml pages) that runs fine on my local machine with IIS Express. Now I'm trying to publish it to a remote server that is running Windows Server 2003 and IIS 6 and has just been upgraded to .NET Framework 4.0.
I was able to successfully publish all the files to the proper directory on the remote server using Visual Studio 2010's Publish dialog (Publish method: FTP), and I've followed the instructions for including all the DLLs needed to run ASP.NET MVC on a machine that doesn't have it installed, but now I'm pretty much stuck.
The first issue is that I don't have access to the remote server's IIS. I may be able to get the hosting company to add a virtual directory or change a setting, but I'm not sure they know what they're doing, and at the moment, I wouldn't know what to tell them anyway.
The second issue is that I need my web app to live inside an existing site (the web app is basically a protected members area of the main website). So, pretend the main site is http://www.foobar.com. I'd like my web app to be accessed by entering the URL http://www.foobar.com/members.
Questions
Is it possible to publish my web app without access to the remote server's IIS?
If not, what exactly do I need to tell the hosting company to add or change in IIS?
Do the settings under the Web tab of project properties affect publishing or just local debugging? At the moment, I have it set to use IIS Express, and the Project URL is "http://localhost:7373/". Do I need to change these?
Given that the remote server is running Windows Server 2003 and IIS 6.0, is it possible to use Web Deploy or am I limited to FTP?
If I can use Web Deploy, what do I put for the Service URL? All I have right now is a URL in the format of ftp://www.foobar.com/www and a username and password.
If I need to use FTP, what steps do I need to take to get the app working once the necessary files have been uploaded to ftp://www.foobar.com/www/members? I'm not worried about database, security certificates, registry, GAC, etc., I just want to know the steps necessary to get the home page of my web app to come up when I put http://www.foobar.com/members.
Have you had a look at this article by Scott Hanselman?
In addition to that article, please read the following thread on StackOverflow on pretty much the same environment as yourself.
Edit
Your first step should be to get the hosting company to set up the virtual directory with the following parameters (IIS 6):
ASP.NET Version: 4.0.30319 (or later)
Local Path: [root ftp path for main website]\Members
[ ] Script source access (unchecked)
[x] Read (checked)
[ ] Write (unchecked)
[ ] Directory browsing (unchecked)
[x] Log Visits (checked)
[x] Index this resource (checked)
Application Name: Members
Execute Permissions: Scripts only
Application Pool: ASP.NET 2.0

Resources