![](/img/trans.png)
[英]A potentially dangerous Request.Path in ASP.NET AjaxActionLink Request
[英]ASP.NET Core 2.1 - Request.Path is empty on production machine
我正在使用 ASP.NET Core 2.1 開發一個小型計算器。 它在我的帶有 ISS Express 的開發機器上運行良好,但是當我將它發布到服務器時,變量Context.Request.Path
似乎存在問題 - 它是空的,而注意到Context.Request.PathBase
不是。
不幸的是Context.Request.PathBase
在開發機器上是空的,所以我不能使用它。
這里有什么問題?
我在Startup.cs
中的Configure
方法
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UsePathBase("/Eleganza");
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
var options = app.ApplicationServices.GetService<IOptions<RequestLocalizationOptions>>();
app.UseRequestLocalization(options.Value);
//app.UseCookiePolicy();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
以及我使用變量的部分
<div title="@Localizer["language"]: @requestCulture?.Provider?.GetType().Name">
<form id="selectLanguage" asp-controller="Home" asp-action="SetLanguage" asp-route-returnUrl="@Context.Request.Path" method="post" class="form-inline" role="form">
@Localizer["language"]: <select class="form-control" name="culture" asp-for="@requestCulture.RequestCulture.UICulture.Name" asp-items="cultureItems" onchange="submitForm();"></select>
</form>
<script type="text/javascript">
function submitForm() {
$('#selectLanguage').submit();
}
</script>
</div>
似乎當您設置基本路徑時, Request.Path 將僅包含基本路徑之后的部分路徑。
https://github.com/dotnet/core/issues/1178#issuecomment-404883599
Also might be related to https://github.com/aspnet/HttpAbstractions/blob/49b447d6265f0de44304b1b887cbdd3227cb038d/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/UsePathBaseMiddleware.cs#L54
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.