Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AspNet Core application “The localhost page isn’t working” error

I have an application developed in asp.net core with full .net framework (.Net 4.6.1). The application is created using Visual Studio 2017 RC. After successful compilation, it has generated TestApplication.exe.

When I go to the project root directory and executes the command dotnet run, application is launched and starts listening on port 5000. Application runs fine using this method. However when I go to the projectRoot\ bin\Debug\net461\ and launch TestApplicatin.exe, it starts listening on port 5000 too but when I go to the browser and type http://localhost:5000 , I get the following error

The localhost page isn’t working

localhost is currently unable to handle this request.

HTTP ERROR 500

Note -

  1. As of now I have not written any piece of code. Entire code is generated by Visual Studio after selecting asp.net core project template.
  2. I don't want to use IIS

Please see the content of Program.cs file

public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .Build();

        host.Run();
    }
like image 819
parag Avatar asked Oct 18 '22 18:10

parag


1 Answers

Found the problem. I was running exe without publishing it. So bin directory contained only exe (i.e. TestApplication.exe) without wwwroot folder. It was not able to find the required files and hence the fatal error was occurring. If you want to run asp.net core application without IIS (i.e. Self Hosted App using Kestrel) following are the correct steps

  1. dotnet restore
  2. dotnet publish
  3. launch the exe from command prompt or double clicking on it. After publishing exe was located at the following path in my case

    bin\Debug\net461\win7-x86\publish\TestApplication.exe

like image 192
parag Avatar answered Oct 29 '22 22:10

parag