c# - 如何从控制器内重定向到 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
解决方案
public ActionResult Questionnaire()
{
return Redirect("~/MedicalHistory.html");
}
推荐阅读
- android - Android 应用显示允许用户交互的经典时钟
- tableau-api - 如何在 Tableau Dashboard 中获取日期范围参数?
- c# - 在 asp.net mvc 中,如何添加验证
- python - Redis-Py AttributeError:“int”对象没有属性“items”
- php - 如何在本地化网站的不同页面中保持语言?
- java - 如何使用 Selenium 运行 Chromium 浏览器?
- javascript - 更改日期格式后无法获取 api
- css - css - 如何内联显示信息块
- angular - 在 2 个单独的 JSON 文件中查找匹配值
- node.js - 如何在 Google Cloud for Node js 项目上上传 HTML 内容?