首页 > 解决方案 > 如何从控制器内重定向到 HTML 页面?

问题描述

用户会收到一封带有链接的电子邮件,他们必须单击该链接才能验证其电子邮件地址。单击链接后,应将用户重定向到两个静态 HTML 页面之一,一个显示“您已获得认证”,另一个显示“链接已过期”

我尝试了几种选择。首先我在Response.Redirect控制器中添加了一个视图路径。我还尝试了在文件中添加 aroutes.MapPageRoute并将RouteConfig重定向调用更改为尝试使用此名称的位置,但这也不起作用。我查看了这个示例以进行修复(重定向到 Views 文件夹中的 html 页面

这是我尝试使用重定向访问 HTML 文件的代码:

EmailCertification.UpdateDBEmailCertified(userName, int.Parse(memberNumber), certSentDT);

return Redirect("~/Views/EmailCertification/EmailCertified.html");`

我得到的错误是:

找不到 /Views/EmailEmailCertification/EmailCertified.html 的路径。我验证了拼写,路径都是正确的。

如果我将代码更改为在 RoutesConfig 中包含 MapPageRoute,它仍然无法正常工作。

这是我的路线配置:

routes.MapPageRoute("HtmlPage", "EmailCertifiedURL", "~/Views/EmailCertification/EmailCertied.html");`

这是我的控制器:

return Redirect("EmailCertifiedURL");

这是我的控制器,它是一个 HttpPost

public ActionResult EmailCertify(string userName, string memberNumber, string certSentDate)
        {
            DateTime certSentDT;

            long lngCertSent = long.Parse(certSentDate);

            certSentDT = new DateTime(lngCertSent);

            if (certSentDT < DateTime.Now.AddDays(-14))
                return Redirect("EmailOldURL");

            EmailCertification.UpdateDBEmailCertified(userName, int.Parse(memberNumber), certSentDT);
            return Redirect("~/Views/EmailCertification/EmailCertified.html");
        }

我得到的错误是

控制器没有操作 EmailCertifiedURL。我从上面提到的 StackFlow 文章中获取了这段代码。

我想要的只是启动控制器操作 EmailCertify 并将我重定向到静态 HTML 页面的电子邮件链接。

https://localhost:44344/EmailCertification/EmailCertify?userName=IS&memberNumber=3000050&certSentDate=636959314302036120 

标签: c#htmlasp.net-mvc-4

解决方案


public ActionResult Questionnaire()
{
   return Redirect("~/MedicalHistory.html");
}

推荐阅读