【问题标题】:URL in MVC 5 asp .netMVC 5 asp .net 中的 URL
【发布时间】:2016-12-16 14:33:17
【问题描述】:

我正在尝试使用 PDF.js 在 MVC 5 应用程序上显示 pdf。

问题是它通过 URL 获取文件名

localhost:32557/Viewer/PDFViewer?filename=thepdffile.pdf

问题是我根据查看器的类型从另一种方法重定向到 PDFViewer

case 5:
   return RedirectToAction("PDFViewer?file=/source/compressed.tracemonkey-pldi-09.pdf", new { id = viewerId});

我得到的网址是

localhost:32557/Viewer/PDFViewer%3ffile%3d/source/compressed.tracemonkey-pldi-09.pdf

我也收到此 URL 的错误

A potentially dangerous Request.Path value was detected from the client (?).

你能帮我解决这个问题吗

【问题讨论】:

  • RedirectToAction("PDFViewer", new { file = "/source/compressed.tracemonkey-pldi-09.pdf", id = viewerId}")?您希望重定向的 URL 是什么样的?
  • 应该是localhost:32557/Viewer/PDFViewer?file=/source/compressed.tracemonkey-pldi-09.pdf
  • 然后省略id = viewerId,首先不清楚应该做什么。您正在重定向到不存在的 action PDFViewer?file=/source/compressed.tracemonkey-pldi-09.pdf。动作为PDFViewer,文件为参数。
  • RedirectToAction 重定向到指定的动作,参数与动作名称分开指定。如果您只想重定向到 URL,请使用 Redirect。因此,如果/Viewer/PDFViewer 实际上是您控制的操作方法(例如ActionResult ViewerController.PDFViewer(string file)),您应该在阅读文档后RedirectToAction。如果没有,你应该使用Redirect
  • 不应该更像 RedirectToAction("PDFViewer", new { file = "/source/compressed.tracemonkey-pldi-09.pdf"});然后在您的 PDFViewer 操作中,它将有一个参数...(字符串文件)

标签: c# asp.net asp.net-mvc asp.net-mvc-5 pdf.js


【解决方案1】:

最后我在@bzlm 的评论的帮助下解决了使用Redirect 而不是RedirectToAction

这么早我用的是

return RedirectToAction("PDFViewer?file=/source/compressed.tracemonkey-pldi-09.pdf", new { id = viewerId})

我可以用这个来代替

return Redirect(baseUrl+"Viewer/PDFViewer?file=/source/compressed.tracemonkey-pldi-09.pdf")

baseUrl 是一个字符串变量,持有localhost:32557/

【讨论】:

    猜你喜欢
    • 2016-01-28
    • 2015-08-02
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-22
    相关资源
    最近更新 更多