I am trying to bring up a application written in ASP.NET CORE 2.1 and Angular 7.
I am using IIS in Windows Server 2016 and installed .NET Core 2.1 Runtime & Hosting Bundle for Windows.
After publishing the solution in Visual Studio 2017, web.config has this content:
<?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=".\Diarias.Web.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: b3f72ccb-207e-461c-b822-2152a37a2311-->
But after trying to start the website, I get this error:
System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.
Your application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.
Program.cs:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Diarias
{
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
}
What is wrong?
Related
I have created a HttpTrigger Azure function (.Net 6.0 Isolated-LTS) using Visual Studio 2022. I have published the Project in a Local Folder in my system. Try to deploy the generated dlls in the Local IIS and call the API from browser but getting error.
I have done all the steps provided in following link:
Is it possible to deploy the Azure Functions in Local IIS?
I have installed Azure Function Runtime and set processPath in web.config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="C:\Program Files\Microsoft\Azure Functions Core Tools\Microsoft.Azure.WebJobs.Script.WebHost.dll" hostingModel="InProcess">
<environmentVariables>
<environmentVariable name="AzureWebJobsStorage" value="UseDevelopmentStorage=true" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
I am still getting the following error:
HTTP Error 500.0 - ASP.NET Core IIS hosting failure (in-process)
I upgraded a few if my web projects to asp.net core 3.0 and am trying to push them to an IIS web server. I installed the .net core 3.0 hosting bundle and runtime and uninstalled the old versions just in case.
I tried to load the page but I get the error:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Error Code 0x8007000d
Config Error
Config File \\?\C:\inetpub\MySite\web.config
Below is my 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="dotnet" arguments=".\MySite.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="">
<environmentVariables>
<environmentVariable name="EXCLUDED_LINE" value="Test" />
<environmentVariable name="COMPLUS_ForceENC" value="1" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Other than the version of .net I haven't changed anything else on the server - I am directly replacing the pervious working projects.
startup.cs:
using System;
using FluentValidation;
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.IISIntegration;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace MySite
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddAuthentication(IISDefaults.AuthenticationScheme);
services.AddTransient<IClaimsTransformation, CustomClaimsTransformer>();
services.AddSingleton<IAuthorizationHandler, CheckADGroupHandler>();
services.AddRazorPages().AddFluentValidation();
services.AddDbContext<MyContext>(options =>
options.UseSqlServer(
"Data Source=MYSERVER\\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints => endpoints.MapRazorPages());
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseCookiePolicy();
}
}
}
project:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<AssemblyName>MySite</AssemblyName>
<RootNamespace>MySite</RootNamespace>
<LangVersion>8</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="2.9.406" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.5.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="3.0.0" />
<PackageReference Include="NLog" Version="4.6.2" />
<PackageReference Include="NLog.Targets.Syslog" Version="5.1.0" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.8.1" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\css" />
<Folder Include="wwwroot\webfonts\" />
</ItemGroup>
</Project>
I tired putting manually copying it to a test IIS and most pages just show error 500, although I can browse the web.config.
I experienced the issue both on a new server and on a server which I uninstalled core 2.2 before installing 3.0. Eventually I found a server that worked and realised I had forgotten to uninstall the old hosting bundle so it had both 2.2 and 3.0
In the end I fixed it by installing the asp.net core 2.2 hosting bundle on the servers alongside asp.net core 3.0 hosting. Site is now working fine.
Asp.Net Core doesn't seem to recognize the user from the call context?.User?.Identity?.Name when windows authentication is enabled and running in IIS Express or IIS.
Desired behavior: Enabling both Windows authentication and anonymous authentication in IIS and/or IIS Express, Asp.Net Core should automatically recognize the windows user.
Actual behavior: When I enable both windows and anonymous authentication in IIS or IIS Express, the user name is null. When I disable anonymous authentication or call HttpContext.ChallengeAsync(IISDefaults.AuthenticationScheme), I get a login prompt, which I don't want.
My understanding is that, even though I want to use this for Active Directory, I don't need active directory or a domain to authenticate a windows user.
Environment:
Windows 8.1 (not on a domain)
IIS 8.5 / Visual Studio 2017 w/ IIS Express
Windows Authentication security feature installed
Windows Authentication & (with NTLM provider) & Anonymous Authentication Enabled
Logged in as local account user
Dependencies:
Microsoft.AspNetCore.All 2.0.8
Startup:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<IISOptions>(iis =>
{
iis.AuthenticationDisplayName = "Windows";
iis.AutomaticAuthentication = true;
});
services.AddAuthentication(IISDefaults.AuthenticationScheme);
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseAuthentication();
app.Run(async (context) =>
{
await context.Response.WriteAsync(JsonConvert.SerializeObject(new
{
UserName = context?.User?.Identity?.Name
}));
});
launchSettings.json:
{
"iisSettings": {
"windowsAuthentication": true,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:51682/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="aspNetCore" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore forwardWindowsAuthToken="true" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
applicationhost.config: (IIS Express)
Based on this article: https://learn.microsoft.com/en-us/iis/configuration/system.webServer/security/authentication/windowsAuthentication/
<authentication>
<anonymousAuthentication enabled="true" userName="" />
<basicAuthentication enabled="false" />
<clientCertificateMappingAuthentication enabled="false" />
<digestAuthentication enabled="false" />
<iisClientCertificateMappingAuthentication enabled="false"></iisClientCertificateMappingAuthentication>
<windowsAuthentication enabled="true">
<providers>
<add value="NTLM" />
</providers>
</windowsAuthentication>
</authentication>
A couple things:
When you disable anonymous authentication, you get a popup because the browser likely doesn't trust the site. You need to open Internet Options (from the Windows Control Panel) -> Security tab -> Click 'Trusted Sites' -> Click 'Sites' and add the URL to your site there. Both IE and Chrome use those settings for deciding whether to automatically send your credentials.
When you have both anonymous and Windows authentication enabled, anonymous takes precedence except in places where you tell it that the user must be logged in. To do that, use the [Authorize] attribute either on a controller, or just on individual actions. There are more details in the documentation, under the heading Allow Anonymous Access.
I've deployed ASP.NET Core 1.1.1 app in IIS-10 on Windows 10 following this tutorial. But when I try to open Modules in IIS, I get the following error [For clear view you can click on the image to zoom in]:
Note:
It's a development machine and already has installed as shown below:
The app pool for the app is as follows:
And the Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
-->
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
UPDATE: Issue may have been related to this post
It turns out that ASP.NET Core Module is installed separately from the SDK and I needed to install ASP.NET Core Module for the above issue to be resolved as explained in this post. Thanks to #natemcmaster for helping me resolve the issue.
I am not able to work with htpphandlers in azure after deploy, it is ok with in the local machine.
In web.config I declared as follows
<system.web>
<httpHandlers>
<add verb="*" path="*.cspx" type="WebRole1.Handle,WebRole1"/>
</httpHandlers>
In my handler.cs file i written as follows.
namespace WebRole1
{
public class Handle : IHttpHandler
{
#region IHttpHandler Members
bool IHttpHandler.IsReusable
{
get { return true; }
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
context.Server.Transfer("Test.aspx", true);
}
#endregion
}
}
In my local machine it is working fine. But after deploy to windows azure getting
500 internal server error.
I think your problem is related with having custom handlers in system.web instead of system.webserver.
Move your custom HTTP Handler to System.webserver as below:
<system.webserver>
<httpHandlers>
<add verb="*" path="*.cspx" type="WebRole1.Handle,WebRole1"/>
</httpHandlers>
<system.webserver>