返回重定向正在创建404 HTTP错误

时间:2019-08-09 00:30:22

标签: c# asp.net-mvc

在我们的网站上,收到来自付款网关的成功付款响应后,我们将用户重定向到“谢谢”页面。控制器操作中重定向到新页面的行是:

return Redirect("~/ThankYou?refid=" + referenceNumber);

控制器设置为:

public class MessageController
{
    public ActionResult ThankYou(string refid = "")
    {
        return View();
    }
}

我创建的路线图为:

routes.MapRoute(
    name: "ThankYou",
    url: "ThankYou",
    defaults: new { controller = "Message", action = "ThankYou", id = UrlParameter.Optional },
    namespaces: new[] { "Portal.Web.Controllers" }
);

当我通过在浏览器上输入website.com/ThankYou?refid=121212来查看页面时,它可以正常工作,但从控制器重定向导致404错误。如何解决错误?

1 个答案:

答案 0 :(得分:1)

您需要像下面这样重定向。 docs

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>localhost</key>
        <dict>
            <key>NSExceptionAllowsInsecureHTTPLoads</key>
            <true/>
        </dict>
    </dict>
</dict>

return RedirectToAction("ThankYou","Message", new { refid = referenceNumber }); 是您的操作,ThankYou是您的控制者,第三个参数 您的Message

修改

以上将形成parameter

另外,获取诸如http://website.com/message/thankyou?refid=121212这样的网址

您将成为http://website.com/thankyou?refid=121212的控制器,并将上述动作传递到其Thankyou动作中,或让MessageController扩展DefaultController(初始启动控制器),然后像下面在Index动作中那样调用

Thankyou