1

1.What I want to do

I am new to C# and now trying to deploy a "ASP.NET web application" to IIS. I tried to follow the steps introduced in this website but instead of the view (Index.cshtml) showing, some directory list shows up when I test “Browse” from IIS.
https://www.guru99.com/deploying-website-iis.html

2.Current Problem

It is currently showing some directory list instead of the view (Index.cshtml).

Showing a directory list



3.What I did

STEP1.Create ASP.NET Core Application

-After adding a project, I added a Controller(HomeController) and a View(Index.cshtml)
-After that I was able to access using IIS Express with URL "https://localhost:44320/Home/Index"

STEP1.Create ASP.NET Core Application

STEP1.Success https://localhost:44320/Home/Index


STEP2.Publish
-Give a Target Folder and generate the application
-The destination I gave a path in “C\TempApp” (Sorry, the path in the image is wrong, I actually gave “C\TempApp”)

STEP2.Publish

STEP3.Add new application in IIS
-Give the Pysycal path " C:\TempWeb\Home\View "
-Give the host as “localhost”

STEP3.Add new application in IIS

STEP4.Test
-Right click the new Application -> Manage Application -> Browse

STEP4.Test

STEP5.Fix Error
Following the message shown in 403 screen, I enable “Directory Browsing” , then I got the following result.

STEP5.Fix Error

2021/1/27 19:00 add

I got advice to check the default page, and it seems the Default page was auto generated to point the View I created.

When I check the "Server Role" setting of IIS, I found ASP.NET and .NET 4.7 is not checked, and estimating that this might be the cause.

IIS Server Role settings

Tatsuya
  • 15
  • 6
  • When you are new to something, always start with the official documentation, not some random posts on the internet https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-5.0 – Lex Li Jan 25 '21 at 13:33
  • Thanks for your advice. I am sorry, I wrote "ASP.NET core" in my initial post, but it was actually "ASP.NET web application". In that case, will the link you told me still OK to follow? Or else, I found this link https://learn.microsoft.com/en-us/visualstudio/deployment/tutorial-import-publish-settings-iis?view=vs-2019 . Is there any advice which to follow ? (And actually I couldn't find an Official MS doc which shows the step of Publish mode "File") – Tatsuya Jan 27 '21 at 00:39
  • Since you edited the question, the problem is rather clear now. All you need to add is a default page for this MVC web app, https://stackoverflow.com/questions/1142003/set-homepage-in-asp-net-mvc – Lex Li Jan 27 '21 at 02:01
  • Thank you very much for your advice. I checked the default document settings in "RouteConfig.cs" and there was already a setting there (I seems auto generated). And it seems working fine, since the default page is successfully shown using the "IIS Express" integrated in VS. Another point I am worried is the components installed in IIS. I added a screenshot in the bottom of the question, but when I choose "Server Roles" for IIS, the ASP 4.5 and .NET 4.5 is unchecked. Does this have anything related to this issue ? – Tatsuya Jan 27 '21 at 10:03

1 Answers1

1

To run the asp.net core site in iis you have to install .net core hosting bundle and runtime.

you can download it from the below link according to your version:

https://dotnet.microsoft.com/download/dotnet-core/3.1

Assign iis_iusrs and iusr permission to the asp.net core site published folder.

Jalpa Panchal
  • 8,251
  • 1
  • 11
  • 26
  • Thank you very much for your advice. I am sorry, I wrote "ASP.NET core" in my initial post, but it was actually "ASP.NET web application". My understanding is ".net core hosting bundle and runtime" is only required for ASP.NET "Core" only, is this correct ? And I also updated my question, so if possible would you please take a look at the new version ? – Tatsuya Jan 27 '21 at 00:41
  • @Tatsuya yes you are right hosting bundle is only needed for the .net core site. and to resolve your current issue you just need to set the default page for your application. – Jalpa Panchal Jan 27 '21 at 06:40
  • Thank you very much for your advice. I checked the default document settings in "RouteConfig.cs" and there was already a setting there (I seems auto generated). And it seems working fine, since the default page is successfully shown using the "IIS Express" integrated in VS. Another point I am worried is the components installed in IIS. I added a screenshot in the bottom of the question, but when I choose "Server Roles" for IIS, the ASP 4.5 and .NET 4.5 is unchecked. Does this have anything related to this issue ? – Tatsuya Jan 27 '21 at 10:03
  • @Tatsuya yes try to enable asp 4.5 and .net 4.5 – Jalpa Panchal Jan 27 '21 at 10:05
  • 1
    Yes this solved the problem. Thanks for your help. – Tatsuya Jan 27 '21 at 13:15