![](/img/trans.png)
[英]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.