.NET 6.0 Razor Pages unable to connect to the localhost - c#

I am working through some tutorials on Razor Pages using .NET 6.0 and have found that my computer is not wanting to find the localhost when running the application. If I create a basic .NET Core Web App using .NET 5.0 then everything works but if I do the same with .NET 6.0 then it doesn't load, even without any changes.
The message I receive is:
This localhost page can’t be found
No webpage was found for the web address: https://localhost:7273/
HTTP ERROR 404
I can open the same project on another computer and everything works as expected. I assume there is something with local setup that is causing this since the standard template for a .NET Core Web App using .NET 6.0 won't even work.
I have attempted to install the .NET Core 6.0 SDK, the Core Runtime, and the Desktop Runtime and nothing changed.
My launch settings file is:
LaunchSettings.json Image
And my Program.cs is: Program.cs Image
I've spent hours searching various forums but there seems to be very little available for .NET 6.0 and nothing seems to hit what I need, especially since the default starter template for a .NET Core Web App won't even work.

I was finally able to find another post that actually matched the issue I was having. The post can be found here: .NET 6 Core Web App Returns web page not found
I was able to confirm that building through dotnet build in the command line did work but I would have to do that every time I made a code change. I then updated visual studio and it works now.

Related

Cannot run (or host) application migrated from .NET Core 2.1 to .NET Core 3.0. and changing the port

I'm trying to migrate my app from .NET Core 2.1 to .NET Core 3.0. I've seen Microsoft document regarding this kind of migration, but I've also seen 2 or 3 tutorials which are way shorter than it and are enough to migrate the app.
I started with changing the <TargetFramework> from netcoreapp2.1 to netcoreapp3.0. As expected, it caused a few issues regarding all the packages, but I resolved it by upgrading them or changing deprecated methods to another.
Now the things are getting weird. I tried to run the application, but got following error:
Could not load type 'Microsoft.AspNetCore.Mvc.MvcJsonOptions' from assembly 'Microsoft.AspNetCore.Mvc.Formatters.Json, Version=3.0.0.0
OK, happens, not the first time I encounter some issue during this migration and probably not last. According to this topic found on Stack, it is because MvcJsonOptions has been removed in .NET Core 3.0. I tried to search for it in my application, but couldn't find any code. Guess it's some internal stuff then. Anyway, most upvoted solution was to update Swashbuckle to version 5.0, so I did. And here comes my troubles:
When I try to run the application, I get "Failed to bind to address http://localhost:5000". This is strange, because few minutes before I've just run this app but in .NET Core 2.1 and it worked perfectly fine. I have checked ports using netstat and port 5000 isn't used by anything. I'm using IIS Express.
When I change the host, I simply cannot run the application. It just loads forever. I've set some breakpoints, but everything looks fine - it just goes through all the code in the Startup.cs, but then it loads infinitely. What seems to be worse, I tried to change the port on another copy of my app, before migrating it to .NET Core 3.0 and it works perfectly fine. Just changed the numbers in appsettings.json and launchsettings.json and it works.
So in summary, my application fails to bind to my standard address after migrating it to .NET Core 3.0 and when I change it, something very strange is happening and it loads infinitely. Any ideas?
MvcJsonOptions has been removed in .net core 3.0. Try installing Newtonsoft.Json NuGet Package and build your project.

.NET Core 2.0 : Vanilla Test Project Windows Auth Failing

I've followed all the documentation for .NET Core 2.0 windows authentication as specified here:
https://learn.microsoft.com/en-us/aspnet/core/security/authentication/windowsauth?tabs=aspnetcore2x
However, no matter how I set up my test project in IIS, I still get "prompted" for credentials even though I am already logged into the domain.
This is different than the behavior in .NET Core 1.0 (where I've set up many windows auth schemes successfully). I also have the required line in Startup.cs:
services.AddAuthentication(IISDefaults.AuthenticationScheme);
At this point, I'm not sure what to do - seems like some sort of issue with IIS serving the site with the new 2.0 auth settings. The strange thing is, when developing locally I do not get any issues (I have "Enable Windows Auth" in the Debug config checked).
All help appreciated..
Fixed now - it turned out that the server was using an old version of AspNetCoreModule for IIS hosting, which was causing weird behavior. I opened an issue on GitHub with the IISIntegration team, so all credit goes to #Thratcher.
GitHub issue:
https://github.com/aspnet/IISIntegration/issues/491
All I needed to do was install the 2.0.3 version of the .NET Core Hosting bundle & everything was magically fixed.

Azure Web App. The specified CGI application encountered an error and the server terminated the process

My app works well locally but I've got an error when I deployed it on Azure Web App:
The specified CGI application encountered an error and the server terminated the process.
My app is a .NET Core 2.0 Web API with no wwwroot folder. I have checked this question, the workaround doesn't work for me and it's about a different .NET Core version. My app creates instance of X509Certificate2 from byte array, I am pretty sure it fails here. I need to dynamically manage X509Certificates - uploading certificate to Web App is not an option.
I also found this in Microsoft Docs:
A known issue with an earlier Kestrel version might cause an ASP.NET
Core 1.0 app that's hosted in App Service to intermittently stop
responding. You also might see this message: "The specified CGI
Application encountered an error and the server terminated the
process."
This issue is fixed in Kestrel version 1.0.2. This version
is included in the ASP.NET Core 1.0.3 update. To resolve this issue,
make sure you update your app dependencies to use Kestrel 1.0.2.
Alternatively, you can use one of two workarounds that are described
in the blog post ASP.NET Core 1.0 slow perf issues in App Service web
apps.
I believe I use latest version of Kestrel dependencies from nuget package:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
I also tried to re-create Web App to make sure there is no junk left and I use everything latest. How can I fix it? Any ideas?
Github issue
I think it might be caused by a missing UseIISIntegration call in your startup code.
Azure Web Apps are based on IIS, so when hosting an ASP.Net Core running with Kestrel, you need this integration to allow IIS to act as a reverse proxy to your service.
Hope it helps!
In Azure App Service it is typically solved by adding a setting:
WEBSITE_LOAD_USER_PROFILE = 1
Some information about it can be found here.

Bot framework missing project.json on deploy

I've developed a bot with Microsoft Botframework using .NET assuming it would run perfectly fine under my linux web host. However, when I publish it to file, transfer it to my linux environment and try to run it with dotnet run I get the following error message:
error DOTNET1017: Project file does not exist '/my/path/bot/project.json'
The project never created a project.json and while I can create one I am beginning to wonder if it is even possible at all to run bot framework under linux at this time. But it seems like everything is on .NET Core so I can't see why not.
I can create the project.json, but I don't know what it should contain. Any ideas?
Unfotunately, Bot Framework isn't on .NET Core yet:
https://www.github.com/Microsoft/BotBuilder/issues/572 https://www.github.com/Microsoft/BotBuilder/issues/1767

Publishing to IIS 8.5 and error 502.5

I always have bad times publishing to IIS 8.5
I have a old project in .NET Core 1.0, but I have made a new project, but this time, in .NET 4.5 (for several reasons)! This new project (.NET 4.5) replaced the old (.NET Core)
In Visual Studio 2015, everything works correctly, then, I build the project, and copied the files to IIS folder (\inetpub\wwwroot).
When I visit the page, I got a error HTTP Error 502.5 - Process Failure.
Then, I remember that the APP Pool was using .NET Core, so, I changed to .NET CLR 4.0, but still no luck.
I don't even known where is the error LOG on IIS to see if I found anything...
I already see the logs on %WINDIR%\System32\LogFiles\HTTPERR and \inetpub\logs\. No error on logs.
All I found about the error 502.5 is that almost always is related to .NET Core (but i'm using .NET 4.5)
Like I posted on comments, the main error was because the Handler Mapper order.
The old project it was a .NET Core project, and the new project, is a .NET 4.5.
For some reason (or my fault), the Handler Mapper was all wrong.

Categories