【问题标题】:Redirect to another website is not working in ASP.NET Core Web Application重定向到另一个网站在 ASP.NET Core Web 应用程序中不起作用
【发布时间】:2019-05-06 07:11:59
【问题描述】:

我只是想打电话:

Redirect("https://www.google.com");

在使用 (Razor Pages) 的 ASP.NET Core Web 应用程序中。请注意,它是绝对最新的模板。

知道为什么什么都没发生吗?

这是我在“关于”页面的模型中的代码:

public class AboutModel : PageModel
{
    public void OnGet()
    {
        Redirect("https://www.google.com");
    }
}

【问题讨论】:

标签: c# asp.net-core asp.net-core-mvc asp.net-core-2.1


【解决方案1】:

您可以在 .cshtml 文件中执行以下操作,如下所示:

@page
@functions
{
    public IActionResult OnGet()
    {
        return Redirect("https://www.google.com");
    }
}

或者如果它只是一个内部页面:

@page
@functions
{
    public IActionResult OnGet()
    {
        return RedirectToPage("/SomePage", new { area = "SomeArea" });
    }
}

请注意,在这两种情况下,Redirect/RedirectToPage 都作为IActionResult 返回。

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-11
    • 2015-08-12
    • 2018-08-07
    • 2014-08-25
    • 1970-01-01
    • 2018-12-11
    • 1970-01-01
    • 2012-04-30
    相关资源
    最近更新 更多