[英]Redirect to another website is not working in ASP.NET Core Web Application
I am simply trying to call:我只是想打电话:
Redirect("https://www.google.com");
In an ASP.NET Core Web Application using (Razor Pages).在 ASP.NET Core Web 应用程序中使用 (Razor Pages)。 Please note it is the absolute latest template.
请注意,这是绝对最新的模板。
Any idea why nothing is happening?知道为什么什么都没有发生吗?
Here is my code in the model for the About page:这是我在“关于”页面的模型中的代码:
public class AboutModel : PageModel
{
public void OnGet()
{
Redirect("https://www.google.com");
}
}
You can just do the following in your .cshtml file, like so:您可以在 .cshtml 文件中执行以下操作,如下所示:
@page
@functions
{
public IActionResult OnGet()
{
return Redirect("https://www.google.com");
}
}
Or if it's an internal page simply:或者,如果它只是一个内部页面:
@page
@functions
{
public IActionResult OnGet()
{
return RedirectToPage("/SomePage", new { area = "SomeArea" });
}
}
Notice that in both scenarios the Redirect/RedirectToPage
are being returned as an IActionResult
.请注意,在这两种情况下,
Redirect/RedirectToPage
都作为IActionResult
返回。
Hope this helps希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.