ASP.NET Core Azure应用服务httpContext.Request.Headers ["Host"]值 [英] ASP.NET Core Azure App Service httpContext.Request.Headers["Host"] Value

查看:251
本文介绍了ASP.NET Core Azure应用服务httpContext.Request.Headers ["Host"]值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天面对的奇怪行为. 我们将使用Azure App Services托管asp.net core 1.1 Web应用程序,并使用路由到特定控制器或区域的子域. 因此,在我的SubdomainConstraint:IRouteConstraint中,我使用

Faced strange behaviour today. We are hosting asp.net core 1.1 web app with Azure App Services and using subdomains that route to a specific controller or area. So in my SubdomainConstraint: IRouteConstraint I use

HttpContext.Request.Headers["Host"]

获取主机名.以前返回的是这样的东西

to get host name. That previously returned smth like that

mywebsite.com or subdomain.mywebsite.com 

从今天(或者可能是昨天)开始,它开始返回我的App Service名称而不是主机名.在本地主机上,一切正常. 通过

Starting today (or a maybe yesterday) it started to return my App Service name instead of host name. On localhost everything works fine. Enumerating through

Context.Request.Headers

在我的一个视图中,我在本地主机上找到了

in one of my Views gives me on localhost:

Accept : 
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding : gzip, deflate, sdch, br
Accept-Language : ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,ca;q=0.2
Cookie : .AspNetCore.Antiforgery....
Host : localhost:37202
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Upgrade-Insecure-Requests : 1

在Azure应用服务中:

in Azure App Service:

Connection : Keep-Alive
Accept : text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding : gzip, deflate, sdch
Accept-Language : ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4,ca;q=0.2
Cookie : AspNetCore.Antiforgery....
Host : mydeploymentname:80
Max-Forwards : 10
User-Agent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36
Upgrade-Insecure-Requests : 1
X-LiveUpgrade : 1
X-WAWS-Unencoded-URL : /
X-Original-URL : /
X-ARR-LOG-ID : 9c76e796-84a8-4335-919c-9ca4rb745f4fefdfde
DISGUISED-HOST : mywebsite.com
X-SITE-DEPLOYMENT-ID : mydeploymentname
WAS-DEFAULT-HOSTNAME : mydeploymentname.azurewebsites.net
X-Forwarded-For : IP:56548
MS-ASPNETCORE-TOKEN : a97b93ba-6106-4301-87b2-8af9a929d7dc
X-Original-For : 127.0.0.1:55602
X-Original-Proto : http

我可以从

Headers["DISGUISED-HOST"]

但是在重定向到登录页面时遇到问题,它使用我的部署名称重定向到错误的URL.

But having problems with redirects to a login page, it redirects to the wrong URL with my deployment name.

想知道我是否可以在任何地方弄乱东西.但是,就像几天前一样,我们已经进行了最后一次部署,此后运行良好.

Wondering if I could mess something up anywhere. But we've made last deployment like a few days ago and it worked fine after that.

推荐答案

这是由AspNetCoreModule中的回归导致的,该回归已部署到Azure App Service中的少量应用程序.此问题正在调查中.请按照

This is caused by a regression in AspNetCoreModule deployed to a small number of apps in Azure App Service. This issue is being investigated. Please follow this thread for status.

这是在部署此修补程序之前可以使用的解决方法:在您的Configure方法(通常在startup.cs中)中,添加以下内容:

Here is a workaround you can use until the fix is deployed: in your Configure method (typically in startup.cs), add the following:

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.Use((ctx, next) =>
        {
            string disguisedHost = ctx.Request.Headers["DISGUISED-HOST"];
            if (!String.IsNullOrWhiteSpace(disguisedHost))
            {
                ctx.Request.Host = new Microsoft.AspNetCore.Http.HostString(disguisedHost);
            }
            return next();
        });

        // Rest of your code here...

    }

这篇关于ASP.NET Core Azure应用服务httpContext.Request.Headers ["Host"]值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆