0

I have create a new ASP.NET Core 2.1 project empty on Visual Studio 2019

This is generated by a line in the Startup.cs file

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }
        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello World!");
        });
    }
}

The application can serve static files HTML from the wwwroot folder.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <p>test</p>
</body>
</html>

The project working on localhost

enter image description here

I need published it to a folder on remote server with SO Windows Server 2008 R2 Enterprise SP2.

I had IIS 7 installed on server.

I installed .Net 4.5.2 and asp.net 2.1 core runtime and asp.net core 3.1 runtime on the server 2008 R2 SP2

I copied the folder contiaining my published Web site to \inetpub\wwwroot on the server.

With this post I configured MVC website in IIS.

https://www.codeproject.com/Articles/1168712/How-to-Quickly-Configure-your-MVC-Website-in-IIS

enter image description here

But on the server the return is

enter image description here

When click on wwwroot project folder

enter image description here

What do I do to give the Web site a URL and otherwise make it active as a Web site?

Maybe I have to install more on the server?

enter image description here

update

Installed on the server

enter image description here

enter image description here

enter image description here

it finally worked thanks to everyone for the support and help

enter image description here

  • VS hides all details from you https://blog.lextudio.com/how-visual-studio-launches-iis-express-to-debug-asp-net-core-apps-d7fd3677e3c3 But once on IIS you need to strictly follow the steps such as `dotnet publish` and ASP.NET Core module. Well, tons for you to learn from various tutorials. – Lex Li Jun 02 '20 at 16:16
  • @LexLi Thanks for reply, sorry but I on't understand your suggestion vs my problem... moreover, the .cshtml pages do not work on the server 2008 R2... could you help me please? –  Jun 02 '20 at 16:51
  • The problem you faced is simply because you don't fully understand how IIS and ASP.NET Core work together. You have to know every words of https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-3.1 and something behind the scene, but that's rather lengthy to go over. BTW, never use a URL with .cshtml. ASP.NET Core MVC apps follow certain URL patterns and none of them expose a .cshtml page explicitly. – Lex Li Jun 02 '20 at 16:55
  • @LexLi Ok, I know this link but the operating systems are supported Windows 7 or later Windows Server 2012 R2 or later... I work with Windows Server 2008 R2 Enterprise SP2 and it cannot be updated, if open on the server http://localhost:901/ without cshtml. the return is the list of folders of project.... thanks –  Jun 02 '20 at 16:58
  • About why localhost link failed, you can get some ideas from https://stackoverflow.com/questions/1142003/set-homepage-in-asp-net-mvc The MVC URL patterns I said above do not include `/` by default, so IIS won't be able to show you anything (and you probably was frightened by the 404.13 error page and went on to enable directory listing. That's wrong and disable it please). – Lex Li Jun 02 '20 at 19:12

2 Answers2

0

We should use DotNet build, DotNet publish command to publish our website rather than copy the project file to the website directory.
https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-3.1&tabs=netcore-cli
In Visual studio, we just need to use the below menu to publish website since VS is a strong, powerful IDE.
enter image description here
Select folder and type the physical path of the website.
enter image description here
At last, we need to install the corresponding Asp.Net hosting bundles(2.1 version instead of 3.1) in order to host Asp.net core web application in IIS.
enter image description here
Result.
enter image description here
Feel free to let me know if the problem still exists.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22
  • Many thanks for help. But if publish my project on server from VS is the existing IIS configuration deleted? Please see **update** image in question. Under **Default Web Site** I have multiple application web and I don't have to delete them –  Jun 03 '20 at 08:55
  • @UncleVince In the `Advanced` of the above publish menu, you could opt in to whether delete the existing file. – Abraham Qian Jun 03 '20 at 10:12
  • it finally worked thanks to everyone for the support and help! –  Jun 03 '20 at 12:18