0
我已经做了一些零件在启动等中间件..迁移到核心,但那些困于旧“模块”(HttpApplication的)
所以这是我的课
public class AcceptQueryMiddleware
{
private const string Realm = "Basic realm=My Sales System";
private readonly RequestDelegate _next;
private static readonly IDictionary<Regex, string> FormatAcceptMap = new Dictionary<Regex, string>();
public AcceptQueryMiddleware(RequestDelegate next)
{
_next = next;
}
public void AcceptQueryHttpModule()
{
RegisterFormatAcceptQuery("csv", "text/csv");
RegisterFormatAcceptQuery("excel", "application/vnd.ms-excel");
RegisterFormatAcceptQuery("nav", "application/navision");
}
private static void RegisterFormatAcceptQuery(string format, string acceptHeader)
{
var regex = new Regex(@"([?]|[&])format=" + format);
FormatAcceptMap.Add(regex, acceptHeader);
}
private static void OnApplicationBeginRequest(object sender, EventArgs eventArgs)
{
var app = sender as HttpApplication;
if (app == null) { return; }
var url = app.Request.RawUrl;
foreach (var format in FormatAcceptMap)
{
if (format.Key.Match(url).Success)
{
app.Request.Headers["Accept"] = format.Value;
break;
}
}
}
public void Dispose()
{
}
}
我如何把它转换成Core?绕过它吗? 特别是在.NET Core中不支持的HttpApplication
..
或者您有任何可以关注的链接或提示吗?
我已经这样做过,但不知何故,我做我的课有点从这个中间件不同。我会回到以前的样子!谢谢 – KakaMir