Remove Server: Microsoft-IIS/8.5 header from Response headers - iis

I have IIS 8.5 installed on my Windows server 2012 R2. I am trying to remove the Server: Microsoft-IIS/8.5 header from my responses.
I tried installed URLScan but it fails to install with the following error
IIS Metabase is required to install Microsoft URLScan Filter v3.1.
I have tried to remove it from the UrlRewrite settings on my website but it's not working. Can anyone please help.

I'm using a custom module to clean my headers inside the app:
public class HeadersCleanupModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PostReleaseRequestState += application_PostReleaseRequestState;
}
void application_PostReleaseRequestState(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("Server");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("ETag");
}
}

Related

413 Error: Payload Too Large - IIS - Windows Server 2016

I'm getting the http response code 413 when I try to upload a large file (>30mb) with an Asp.Net core mvc controller deployen on a windows server 2016.
The web service is running on IIS ("In process").
The controller looks like:
[Route("api/[controller]")]
[ApiController]
public class FileController : ControllerBase
{
[HttpPost]
[DisableRequestSizeLimit]
[DisableFormValueModelBinding]
public async Task<ActionResult<Guid>> Upload(IFormFile file)
{
[...]
}
}
I'm using this setting in the startup class:
public void ConfigureServices(IServiceCollection services)
{
[...]
services.Configure<FormOptions>(x =>
{
x.MultipartBodyLengthLimit = long.MaxValue;
});
}
And I have those settings in my app web.Config to prevent request size limit:
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<serverRuntime maxRequestEntityAllowed="4294967295" uploadReadAheadSize="2147483647" />
</system.webServer>
This is working perfercly when I run it locally on my machine (windows 10 + IIS)
But as soon I publish the solution on the windows server 2016 machine I get the 413 error when I try to uplad a file >30mb.
Note: the applicationHost.Config on the server is allowing the override of the sections:
system.webServer/security/requestFiltering/requestLimits
system.webServer/serverRuntime
I realized the .net core hosting bunble version was not the same on my machine 3.1.3 than the server machine 3.1.2.
After updating it on the server with the latest available version, the upload of large files started to work without generating 413 error.

tzsk\payu package for laravel 7.3.0 after payment redirect gives 419 error

I have installed version of laravel 7.3.0. and installed a package for payumoney tzsk\payu(4.0). It works well till the payment. after payment done when it redirects back it gives 419 error.
This is the url I am getting after payment process done.
http://127.0.0.1:8000/tzsk/payment/success?_token=RNZTbKx8Ru1VWa2rasf sad9fq9qLcttbtPvDJXpYM&callback=aHR0cDovLasdfasdfasdfbnQtcGFja2FnZS1wYXltZW50L3N0YXR1cw==
You can also generate this error by installing new laravel and tzsk\payu package.
tzsk have fixed this issue in his package for temporary. Please check at https://github.com/tzsk/payu for more information.
Added following code in src/Controllers/PaymentController.php
class PaymentController extends Controller
{
/**
* Temporarily set cross site on
*/
public function __construct()
{
config(['session.same_site' => null]);
}

.NET Core Linux Kestrel https configuration

We are deploying our first .NET Core application on Linux (Ubuntu 18.04 LTS and Apache2).
We do not know the certificates of the servers where they will be deployed nor the ports where they will be deployed, since they are the client's and we do not have access, so we need to be able to enter them by configuration in the appsettings (Kestrel configuration).
In windows the api works without problems in both http and https, putting this configuration in the appsettings.json and reading it in the Startup.cs like this:
// kestrel configuration
services.Configure<KestrelServerOptions>(Configuration.GetSection("Kestrel"));
Our windows configuration of the appsettings.json is:
"AllowedHosts": "*.mydomain.es;*.mydomain-eu.com;test-win;test-linux;localhost;127.0.0.1;*.myActiveDirectoryDomain.ad",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5009"
}
,"Https": {
"Url": "https://localhost:5010"
}
}
}
When deployed on Linux with the same configuration, the Kestrel service does not start. Kestrel service error:
sudo systemctl status kestrel-apieu.service
● kestrel-apieu.service -
Example ASP .NET Api running on Ubuntu 18.04 Loaded: loaded
(/etc/systemd/system/kestrel-apieu.service; enabled; vendor preset:
enabled) Active: activating (auto-restart) (Result: core-dump)
since Thu 2020-02-06 09:13:20 CET; 4s ago Process: 4449
ExecStart=/usr/bin/dotnet
/var/www/core/api/apieu/HHHHH.JJJJJJJJ.Api.UnitsEuApi.dll
(code=dumped, signal=ABRT) Main PID: 4449 (code=dumped, signal=ABRT)
Removing the https part works in http without any problems, like this:
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5009"
}
}
}
Kestrel service running:
sudo systemctl status kestrel-apieu.service
● kestrel-apieu.service -
Example ASP .NET Api running on Ubuntu 18.04 Loaded: loaded
(/etc/systemd/system/kestrel-apieu.service; enabled; vendor preset:
enabled) Active: active (running) since Thu 2020-02-06 09:16:19
CET; 2s ago Main PID: 5504 (dotnet)
Tasks: 17 (limit: 4660) CGroup: /system.slice/kestrel-apieu.service
└─5504 /usr/bin/dotnet /var/www/core/api/apieu/HHHHH.JJJJJJJJ.Api.UnitsEuApi.dll
When we set this configuration, to the server's self-signed certificates .crt the Kestrel service lifts but does not work on https.
Configuration appsetings:
"AllowedHosts": "*.mydomain.es;*.mydomain-eu.com;test-win;test-linux;localhost;127.0.0.1;*.myActiveDirectoryDomain.ad",
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5009"
}
,"Https": {
"Url": "https://localhost:5010", // we also tried: "https://*:5010"
"Certificate": {
"Path": "/etc/apache2/ssl/apache.crt",
"Password": "/etc/apache2/ssl/apache.key",
"AllowInvalid": true
}
}
}
http://localhost:5009/test work's perfectly, but https://localhost:5010/test send error:
Secure Connection Failed
An error occurred during a connection to localhost:5010.
PR_END_OF_FILE_ERROR
The page you are trying to view cannot be shown because the authenticity of the received data could not be verified.
Please contact the website owners to inform them of this problem.
But the self-signed certificate does allow you to enter https://localhost without problems (once you trust the certificate).
We have also tried to convert the self-signed .crt certificate to .pfx (with OpenSSL -> convert crt to pfx certificate) and configure it this way:
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://localhost:5009"
}
,"Https": {
"Url": "https://*:5010",
"Certificate": {
"Path": "/etc/apache2/ssl/apache.pfx",
"Password": "passwdExport"
,"AllowInvalid": true
}
}
}
}
But it also doesn't lift the service and it doesn't work on either http or https.
We've looked at all these help pages, among others:
.net core Kestrel server SSL issue
Certificate issue in Kestrel ssl JSON configuration using .net Core 3.1
Asp.Net Core 2.0 HTTP -> HTTPS on Kestrel
Will a self-signed certificate work behind an Apache reverse-proxy?
The problem seems to be that we're not properly configuring the Kestrel with the self-signed certificate. But we can't find our mistake. Can you help us?
In case you can give more information we opened another previous post, it was more generic because we did not know that the problem came from the Kestrel but we thought it was from the Apache2: deploy NET Core Linux HTTPS SSL
I use .net6 and reccomend you to try this :
"Kestrel": {
"EndPoints": {
"Https": {
"Url": "https://domain:port",
"Certificate": {
"Path": "path_to.pfx",
"Password": "password"
}
}
}
}
And in your Program.cs file enter this:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
#if RELEASE
webBuilder.UseKestrel();
#endif
webBuilder.UseStartup<Startup>();
});
It will help you!
Also useful links:
https://learn.microsoft.com/en-us/answers/questions/613333/loading-certificatepfx-with-password-in-linux-does.html
https://learn.microsoft.com/ru-ru/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0

Unable to start Kestrel. System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use

I followed the steps from this URL to publish .NET core 2.1 web application code to Linux Centos 7 server.
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-2.2
I tried to run "sudo dotnet application_name.dll". I received this following error message. Am I missing something? I published code using Visual Studio 2017 on windows machine and copied code to Linux server.
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use. ---> Microsoft.AspNetCore.Connections.AddressInUseException: Address already in use ---> System.Net.Sockets.SocketException: Address already in use
Program.cs
public class Program
{
public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
}
Startup.cs config
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
}
launchSettings.json:
"applicationUrl": "https://localhost:5001;http://localhost:5000"
Restarting this service may fix the issue : Host Network Service on windows Services program
Goto Powershell in admin mode and write the following command:
netsh interface ipv4 show excludedportrange protocol=tcp
Check port exclusion ranges whether your port falls under this list; if yes then use the following commands:
net stop winnat
net start winnat
The issue should be resolved.
In my case, I was able to work around this by changing the port Kestrel was using. Here are two options that worked for me (pick one):
Add an "applicationUrl" setting to the launchSettings.json file (found under the Properties folder in VS2019). Using "https://localhost:5201" in the example below:
"profiles": {
"IIS Express": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"Host": {
...
}
},
"Your.App.Namespace.Api": {
...
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5201;http://localhost:5200"
}
}
Add a "UseUrls" fluent method invocation to the WebHostBuilder in Program.Main(). i.e. "http://localhost:5200/" in the example below:
using (var host = new WebHostBuilder()
.UseKestrel(o => o.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30))
...
.UseStartup<Startup>()
.UseUrls("http://localhost:5200/")
After Windows 10 Update KB4074588, some ports are reserved by Windows and applications cannot bind to these ports. 50067 is in the blocked range.
You can use netsh interface ipv4 show excludedportrange protocol=tcp to list the reserved ranges.
excludedportrange list
ref Issue: https://superuser.com/questions/1486417/unable-to-start-kestrel-getting-an-attempt-was-made-to-access-a-socket-in-a-way
I just restart IIS then remove and create a website again and it's works fine!
If you are using Mac "Kestrel doesn't support HTTP/2 with TLS on macOS and older Windows versions such as Windows 7" please see https://learn.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-6.0#unable-to-start-aspnet-core-grpc-app-on-macos for more details. A quick fix (only DEV ) is to remove the HTTPS URL from applicationUrl in the launchsettings.json
...
"applicationUrl": "http://localhost:5126",
...
This issue is easily resolved by changing the Port number.
This works for me with Windows 10
Open CMD Prompt as Administrator and run:
net stop hns
net start hns
Killing processes by port, restarted my Visual Studio, but did not solve my problem.

ASP.NET Core 2.0 on IIS error 502.5

I install .net core 2.0 to my windows server 2008
I have two web project. Both of them work in my PC. But when I publish to my server one project work very well but other give that error
HTTP Error 502.5 - Process Failure
Application 'MACHINE/WEBROOT/APPHOST/KI-TAP.COM'
with physical root 'C:\HostingSpaces\Reseller1\ki-tap.com\wwwroot\'
failed to start process with commandline
'dotnet .\ki-tap.dll', ErrorCode = '0x80004005 : 8000808c.
I update my windows server but it still gives the same error.
here is my program.cs (I didn't add code here. This is default)
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
and here is my web.config (published and default code )
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\ki-tap.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
and here is my startup.cs(I added session configuration)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace ki_tap
{
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.AddMvc();
services.AddSession();
}
// 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.UseBrowserLink();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSession();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Edited:
with #set suggestion, I run that command in windows server 2008 in cmd console
C:\Program Files (x86)\dotnet\dotnet myProjectPath\project.DLL
it gives the below error. What should I do?
package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.1'
path: 'lib/netstandard2.0/Microsoft.AspNetCore.Antiforgery.dll'
his assembly was expected to be in the local runtime store as the application
s published using the following target manifest files:
aspnetcore-store-2.0.3.xml
You may have the same problem as described here in aspnet/IISIntegration repo. The solution is to add the following into .csproj file:
<PropertyGroup>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
And in general, the source of this problem is that the dotnet version on your local computer and the dotnet version on the server are different.

Resources