Login issue after publishing .Net Core 3.1 web app to IIS - authentication

I created a .Net Core 3.1 MVC application that is using induvial user accounts as authentication. I deployed the site to IIS, which works. However when I tried to log in with an account I know that works, the login does not succeed, and I am directed back the default route of the application. No error messages or log entries that I can find. The application pool is set up for non managed code, and is running under an account that has dbo rights to the database. Any thoughts as to what the issue might be?
http://localhost:44360/ running on server on Visual Studio 2022
http://localhost:2710/ running on server on IIS
http:// domain . com not working

It is difficult for everyone to help you without error messages. Have you tried swapping to a development environment to see the details of the error?
Locate the Web.config file and adjust it to set the ASPNETCORE_ENVIRONMENT environment variable as follows:
<aspNetCore processPath="dotnet" arguments=".\ProjectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
This method worked for me to find the error, you can try it.

This field already exists in the web.config file.
It gives a warning when the user is wrong, but when we enter the correct user information, it does not create cookies or sessions and does not fall into any errors.

Related

problem when publishing asp.net core project on a server

I'm implementing asp.net core project. I published my project into a package and set it on a main server, but, the database was set on another server. To do that, in the part of connection string of appsetting file, I just changed the server name and database name and when running the project I confront with the following error:
I appreciate if anyone can suggest me a solution for it.
This error indicates that an exception has occurred in your project, but since it is not a development environment, it is impossible to show you the real error message.
If you want to get the real error information, you can try to change the value of the ASPNETCORE_ENVIRONMENT variable from Production or other to Development in web.config file, and then refresh to see the real error information.
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
For more details, please refer to this discussion.

Unable to run my .net core app in local as well as on server with IIS

I created a .net core api (version 2.2.0) and I'm getting the following error when I try to run on IIS.
The application process failed to start The application process
started but then stopped The application process started but failed to
listen on the configured port
I verified my web config and it appears to have correct set of values.Enabled logging and log file comes as empty.
Event log shows the following error.
I installed hosting bundle and checked still getting same error. Also tried giving permission to IIS_IUSRS to the output folder. It didn't make any difference. Having said that error code "'0x80004005' " suggests a permission error. Still couldn't figure it out. Appreciate any help !
Web config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyApi.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>`enter code here`
<!--ProjectGuid: 4d7644bb-9348-46f9-8397-95f01e03d599-->
Make sure you publish the site properly in iis. Your site root folder has enough permission to access it by iis. assign the iis_iusrs and iusr permission to the site folder. your application pool identity is set application pool identity or local system. anonymous authentication is enabled. and you installed the iis asp.net feature. make sure your site binding is correct and the application pool is using correct .net version and running under integrated application pool.
The reason behind the error message
The HTTP Error 502.5 - Bad Gateway and HTTP Error 502.5 - Process
Failure error messages occur in ASP.NET Core when IIS fails to execute
the dotnet process.
.NET Core Runtime is not installed
web.config file has not been transformed
To resolve this issue you could refer one the below-suggested way:
Install the .NET Core Runtime
The most common reason for this to occur is when you haven't installed the .NET Core runtime on the server.
You can download the latest .NET Core runtime from Microsoft's .NET download page.
After installing Bundle stop iis and start again.
Publish a Self-Contained Deployment
If you don't want to install the .NET Core Runtime. An alternative for .NET Core web applications is to publish them in the Self-Contained deployment mode, which includes the required .NET Runtime files alongside your application.
If you go with this option, you'll also need to choose a target runtime: win-x86, win-x64, osx-x64, or linux-x64. Because self-contained deployments are not portable.
Transform your web.config file
Another reason for this error to occur is when you deploy an untransformed web.config file.
This is likely to be your issue if you had a previously working web application and merely deployed a new version of it.
In ASP.NET Core applications, the web.config file contains a handler that directs requests to the AspNetCoreModule and an aspNetCore element that defines and configures the ASP.NET Core process to execute your web application.
Here is a minimal web.config file for an ASP.NET Core application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
The issue is The untransformed web.config contains the variables %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct paths. When IIS tries to run ASP.NET Core, it uses %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct path and arguments.
To fix the HTTP Error 502.5 in ASP.NET Core, you need to transform the web.config and replace the untransformed web.config file on the IIS web server.
steps to transform web.config file:
This transformation takes place when you choose to publish your web application. The transformed web.config ends up in the published output folder. Therefore, you simply need to publish your web application and copy the resulting web.config file onto the server.
In a transformed web.config file, the aspNetCore element will look something like this:
<aspNetCore processPath="dotnet" arguments=".\MyApplication.dll" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
%LAUNCHER_PATH% has been replaced by dotnet and %LAUNCHER_ARGS% has been replaced by the path to the main web application dll .\MyApplication.dll.
links:
Publish an ASP.NET Core app to IIS

"500 - Internal server error" when calling ASP.NET Core 2.1 Web API on Windows Server

I have an ASP .Net Core 2.1 Web API which I've deployed to a new server we recently purchased (running Windows Server 2016 Standard). The API works perfectly on both my development PC and our old server (running Windows Server 2012 R2). But on this new server, I get this error:
500 - Internal server error.
There is a problem with the resource you are looking for, and it cannot be displayed.
I remember a year ago also struggling a lot trying to get it to run on our old server. I did eventually get it to work, but I can't remember what I did! Is there any way to get more information on this error? I've checked the Windows Event Viewer on the new server and there is nothing there. Also, although I've got stdoutLogEnabled="true" in my web.config, it's not generating the log - and I've created the \logs\stdout path so the folders do exist...
I've also got app.UseDeveloperExceptionPage(); in my Startup.cs, but I'm not getting any more info that a simple 500 internal server error.
This is what my web.config looks like:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\PropWorx.API.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: cfa62a1f-c5f6-43f8-bcbe-04068e40b803-->
I've also got the Microsoft .NET Core 2.1.1 - Windows Server Hosting installed and the Microsoft .NET Core Runtime - 2.1.1 installed (both x86 and x64).
Like I said it works on my development PC and on our old server, so it must be a configuration issue on the new server. Is there a way I can get more detailed error information other than just 500 Internal Server Error?
I had an outdated version of the .NET Core Windows Server Hosting bundle. I had version 2.1.1 installed. I removed it, and installed version 2.1.4 and now it works.
Various reasons can cause this issue.
if this is happening only in the browser (working with curl or postman), it can be a pre-flight request error, then you will need to modify UrlScan.ini (I assume this didn't changed on Windows 2016) at the following path (C:\Windows\System32\inetsrv\urlscan), add OPTIONS to [AllowVerbs].
if not, make sure you followed the steps provided in Microsoft documentation:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.1&tabs=aspnetcore2x
You may need to install Visual C++ 2015 Redistributable on the server
To get logs, change "IncludeScopes": true, in your appsettings.json logging section, check also the event viewer.

.NET Core endpoint not found after setting to app url

A member of my team set an API Endpoint as the App URL in the project properties of an ASP.NET Core 2 application. After doing so and then removing it, we can no longer access the endpoint and receive a 404 error.
This only happens when running under IIS Express. When I switch to my local IIS it works just fine. Switch back to IIS Express, 404 again. We are using Visual Studio 2017.
There are no lingering settings in the launchSettings.json, web config, or project file that I have found.
Any ideas what would cause this?
EDIT:
Initial IIS EXPRESS App URL: http://localhost:8085
If I change that to http://localhost:8085/api/values nothing works.
So, I change it back to http://localhost:8085
Now, I cannot get to http://localhost:8085/api/values in the web browser. It's like setting the endpoint as the app URL just killed it.
Alan Silva was correct.
The below lines were in the applicationhost.config. Deleting them caused the expected behavior.
<application path="/Values" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Repository\TEst\WebApplication1\WebApplication1" />
</application>
<application path="/api/Values" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Repository\TEst\WebApplication1\WebApplication1" />
</application>
IIS express is hosting your application in a different port than your local IIS. I suggest you to run your application on IIS express, check the port that is being used and change the endpoint url accordingly.

ASP.NET Core 1.0 Web.Config Issue

My first stab at trying to implement an ASP.NET Core Application to Hosted IIS Server.
I believe I could a malformed XML aspNetCore Attribute of the web.config
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
%LAUNCHER_PATH% is a placeholder.
based on this information
I changed the processPath="dotnet" and arguments=".\WebDevX1.dll" however running with that produces 502.5 Error. Running with just placeholders works fine. It was my understanding that I need to change those placeholders in order to publish to the Hosted Server.
Whether I modify the placeholders in those 2 attributes or not, the web.config aspNetCore Attribute still shows an error
When I run locally from Visual Studio, the web.config reverts back to the placeholders:
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%"
ASP.NET Core 1.0.0 is installed locally
And my Host indicates they support .NET Core defaultly.
If someone has any insight as to what I'm missing I would really appreciate it.
You should have the publish-iis tool configured to run as a post-publish script. This tool replaces LAUNCHER_PATH and LAUNCHER_ARGS. You can find more details about this in my post about running ASP.Net Core applications with IIS.
After project.json to .csproj transition the publish-iis tool was converted to an MSBuild task (the TransformWebConfig task)