我们正在尝试实现一个非托管标头,它可以*.website.com
在 ASP.NET 中接受之前的任何内容。由于它将接受任何子域,我们扩展了 HttpContextBase 类以添加自定义方法。
public static bool ValidateHost(this HttpContextBase context)
{
var domain = context.Request.Url.Host;
//add logic to check if the host is valid and the subdomain exist in the database
return false;
}
此方法将验证context.Url.Host
数据库中是否存在有效主机或其子域,如果不存在则将请求重定向到默认主机website.com
。为此,我在下面添加了这行代码BaseController
:
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (!filterContext.HttpContext.ValidateUrl())
{
filterContext.HttpContext.Response.Redirect("https://website.com/");
return;
}
}
每当它返回时,它都会重定向到默认主机false
,但是它会引发异常:{"Server cannot append header after HTTP headers have been sent."}
我在这里遗漏了什么还是逻辑不完整?