简体   繁体   English

域别名 - 如何确定在 .net core 3.1 中使用了哪个?

[英]Domain alias - how to determine which one was used in .net core 3.1?

I have a web app using .net core 3.1 on IIS 10. I have my main domain set up and I have 3 alias domains that resolve to the main domain name.我有一个在 IIS 10 上使用 .net core 3.1 的 Web 应用程序。我设置了主域,并且有 3 个解析为主域名的别名域。 For my app I want to know which domain the user used to access the site.对于我的应用程序,我想知道用户用于访问该站点的域。

How could I determine that?我怎么能确定呢? Any help to get me pointed in the right direction would be great.任何让我指向正确方向的帮助都会很棒。

Thanks!谢谢!

If I understand this correctly, an alias domain is just an additional domain which points to the same server as your main domain, so you are not being redirected to the main domain?如果我理解正确,别名域只是一个附加域,它指向与您的主域相同的服务器,因此您不会被重定向到主域? Ie the address bar still shows the URL the user used to access your site.即地址栏仍然显示用户用来访问您的站点的 URL。 In that case, it should be as easy as reading the host name from the current URL.在这种情况下,它应该像从当前 URL 读取主机名一样简单。 You can grab that info via the IHttpContextAccessor .您可以通过IHttpContextAccessor获取该信息。

Step 1, register it as a service in the startup.cs file第一步,在startup.cs文件中将其注册为服务

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

Step 2, make your controller depend on it, via DI:第 2 步,让你的控制器依赖它,通过 DI:

private readonly IHttpContextAccessor _httpContextAccessor;
public YourController(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}

Step 3, read the info from the httpContextAccessor:第 3 步,从 httpContextAccessor 读取信息:

string domain = _httpContextAccessor.HttpContext.Request.Host.Value;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 C# 和 .NET Core 3.1 中显示一个表的值对应于另一个表的单元格值(有或没有连接)? - How to display values of one table which corresponds to a cell value of another table (with or without joins) in C# and .NET Core 3.1? 如何在 .net core 3.1 中删除一个 Controller Action 的 CORS 限制 - How to remove CORS restriction for one Controller Action in .net core 3.1 如何确定ASP.NET Web解决方案使用哪些表? - How to determine which tables are used by ASP.NET web solution? 在运行时如何确定使用哪个单声道版本? - At runtime how does one determine which mono version is being used? 如何确定asp.net核心应用程序将在哪个环境中运行? - How to determine which environment asp.net core app will run in? 如何在 .NET Core 3.1 的 C# 中检索域用户的所有本地组? - How can I retrieve all the local groups for a domain user in C# in .NET Core 3.1? 如何将外部域绑定到 .NET Core 3.1 Kestrel 自托管应用程序? - How to bind external domain to .NET Core 3.1 Kestrel self-hosted application? 当在 Blazor 应用程序中使用 Azure Active Directory 时如何在 asp net core 3.1 中自定义注销页面 - How to customize sign out page in asp net core 3.1 when Azure Active Directory used in a Blazor application 如何测试在 .NET Core 3.1 中的响应内容中不返回数据的控制器 POST 方法? - How to test a controller POST method which returns no data in response content in .NET Core 3.1? "如何编写参数为字符串列表的存储过程 [ SQL Server,ASP.NET Core 3.1 ]" - How to write a stored procedure in which the parameters are a list of strings [ SQL Server, ASP.NET Core 3.1 ]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM