ASP.NET核心将子域映射到区域

编程入门 行业动态 更新时间:2024-10-25 16:23:21
本文介绍了ASP.NET核心将子域映射到区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将子域映射到区域,到目前为止,我发现的所有答案都是针对.NET的以前版本,而不是.NET core.我发现的最佳和最相关的答案来自此页面.但是,我在实现它时遇到了问题,因为它似乎是.NET Core以前版本的演练,并且出现了'MvcRouteHandler' does not contain a constructor that takes 0 arguments错误.

I am trying to map the subdomains to areas, So far all the answers I found were for pervious versions of .NET and not .NET core. the best and most relevant answer I found was from This page. however i am having a problem implementing it as it appears to be the walkthrough for a pervious version of .NET core and i am getting the 'MvcRouteHandler' does not contain a constructor that takes 0 arguments Error.

这是我从中得到错误的代码:

Here is the code which i get the error from:

public class AreaRouter : MvcRouteHandler, IRouter //the error happens in this line, visual studio underlines the AreaRoute word { public new async Task RouteAsync(RouteContext context) { string url = context.HttpContext.Request.Headers["HOST"]; string firstDomain = url.Split('.')[0]; string subDomain = char.ToUpper(firstDomain[0]) + firstDomain.Substring(1); string area = subDomain; context.RouteData.Values.Add("area", subDomain); await base.RouteAsync(context); } }

所以无论如何,我正在寻找另一种方法来将子域映射到区域或找到解决此错误的方法.

so anyway, i am looking for another way to map subdomains to areas or find a way to fix this error.

推荐答案

完整的教程可用此处. 设法创建文件的工作版本. 1.可以在此处获得路由器代码.在文件顶部的_allowedSubdomains数组中指定您自己的子域. 2.添加路由器后,在Startup.cs中更改代码:

Complete tutorial available here. Managed to create working version of your file. 1. Code for Router is available here. Specify your own subdomains in _allowedSubdomains array on top of file. 2. After adding router, change your code in Startup.cs:

app.UseMvc(routes => { routes.DefaultHandler = areaRouter;

areaRouter应该按照@mepsi的说明进行传递. 3.最后,按照此处所述,允许使用sudomain. 现在一切都应该正常工作.完整的代码可在 Github 上找到.稍后,我将编写完整的教程并提供所有解释.

areaRouter should be passed as described by @mepsi. 3. Finally, allow the use of sudomains as described here. Everything should be working now. The complete code is available on Github. I will write complete tutorial with all explanations later.

更多推荐

ASP.NET核心将子域映射到区域

本文发布于:2023-07-16 04:17:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:核心   区域   ASP   NET   将子域

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!