当ASP.NET Core URL重定向失败且没有错误信息时,可能是由于以下几个原因导致的:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
//...
}
public IActionResult RedirectAction()
{
//...
// Example of redirecting to an action with parameter
int id = 1;
return RedirectToAction("Details", new { id = id });
//...
}
public IActionResult Details(int id)
{
//...
return View();
}
public IActionResult RedirectAction()
{
//...
// Example of using RedirectToAction
return RedirectToAction("Index", "Home");
//...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseHttpsRedirection();
//...
}
public async Task RedirectAction()
{
//...
// Example of redirecting after an async operation
await _someService.DoSomethingAsync();
return RedirectToAction("Index", "Home");
//...
}
如果以上解决方法都没有解决问题,可以尝试在程序中启用详细的错误日志记录,以便更好地定位问题。可以通过在Configure方法中添加app.UseDeveloperExceptionPage()来启用开发者异常页面,或者在appsettings.json文件中设置"Logging:LogLevel:Default"为"Debug"来启用详细日志记录。
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseDeveloperExceptionPage();
//...
}
{
//...
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
//...
}
希望以上解决方法能帮助您解决ASP.NET Core URL重定向失败且没有错误信息的问题。如果问题仍然存在,请检查其他相关因素,例如网络连接、防火墙设置等。