简体   繁体   English

重定向到另一个网站在 ASP.NET Core Web 应用程序中不起作用

[英]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.

相关问题 如何在重定向到asp.net Core 2.0中的另一个Web应用程序之前先处理数据 - How to massage data before redirect to another web application in asp.net core 2.0 asp.net mvc 4作为Web应用程序而不是网站 - asp.net mvc 4 working as web application not as a website 将ASP.NET Web应用程序转换为ASP.NET WebSite - Convert ASP.NET Web Application to ASP.NET WebSite 调试 IIS 网站时,ASP.NET Core 2 Web 应用程序未加载用户机密 - ASP.NET Core 2 web application isn't loading user secrets when debugging IIS website 缺少“ASP.NET Core Web 应用程序(.NET Core)”模板 - missing “ASP.NET Core Web Application (.NET Core)” template 如何在ASP.NET MVC 4 Web应用程序中从一个控制器的视图重定向到另一个控制器的视图 - How to redirect to a View of another Controller from one Controller's View in ASP.NET MVC 4 Web Application 处理身份验证/授权:ASP.NET Core Web 应用程序 => ASP.NET Core Web API => SQL - Handling authentication/authorization: ASP.NET Core Web Application => ASP.NET Core Web API => SQL Asp.net为web-api解雇重定向的核心授权 - Asp.net core authorization for web-api firing redirect 将文件从 ASP.NET Core web api 发布到另一个 ASP.NET Core web api - Post files from ASP.NET Core web api to another ASP.NET Core web api 如果网站创建为 Visual C# ASP.Net Web 应用程序在 VS2015 中,PageMethods 不起作用 - PageMethods not working if the website is created as a Visual C# ASP.Net Web Application in VS2015
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM