[英]Where to place HttpContext.Current.RewritePath in ASP.NET 5?
[英]Asp.Net Core HTTPContext and RewritePath
我正在将旧的HttpModule
转换为新的MiddleWare
并想知道在MiddleWare
重写路径的正确方法是什么。
旧模块使用此:
context.RewritePath(path, string.Empty, queryPart);
对于简单的规则,您应该能够通过中间件在context
更改request.Path
[, Scheme
, Host
, QueryString
]。 如下所示,并确保您的中间件在管道中尽早运行:
internal class PathRewritingMiddleware
{
private readonly RequestDelegate _next;
public PathRewritingMiddleware(RequestDelegate next)
{
_next = next;
}
public Task Invoke(HttpContext context)
{
context.Request.Path = "elsewhere/" + context.Request.Path;
return _next(context);
}
}
就是说, 不要那样 ,因为ASP.NET Core已经为您想到了所有这些 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.