简体   繁体   English

Server.MapPath 和 window.open()

[英]Server.MapPath and window.open()

I'm actually working on an app that provides the possibility to the users to upload the files they wish.我实际上正在开发一个应用程序,它为用户提供上传他们想要的文件的可能性。 Those files should also be visualizable once uploaded.上传后,这些文件也应该是可视化的。

In order to do that I'm trying to get the file path with Server.MapPath and a concatenation of other values.为了做到这一点,我正在尝试使用 Server.MapPath 和其他值的串联来获取文件路径。 The file path is passed as an argument in a window.open javascript function.文件路径在 window.open javascript 函数中作为参数传递。

My problem is that I do not get any result at all.我的问题是我根本没有得到任何结果。 No window is opened.没有窗口打开。

Here is my code:这是我的代码:

string completeUrl = Server.MapPath(ConfigurationManager.AppSettings["UsersImagesUploadFolder"] + CurrentUserLogin +
                               @"\\" + ((GridDataItem) e.Item)["Url"].Text);

string radWindowOpen = "<script type='text/javascript'>window.open('" + completeUrl + "')</" + "script>";
 Page.ClientScript.RegisterStartupScript(this.GetType(), "fileDisplay", radWindowOpen);

I'm probably missing something obvious but I don't see what it is.我可能遗漏了一些明显的东西,但我不明白它是什么。

Thank you for your answers.谢谢您的回答。

As Damien has pointed out, Server.MapPath is used for server side path mapping.正如 Damien 所指出的, Server.MapPath用于服务器端路径映射。 Clients need to see a path underneath your web app.客户需要看到您的 Web 应用程序下方的路径。

For example:例如:

Page.ResolveUrl("~/uploads/" + ConfigurationManager.AppSettings["UsersImagesUploadFolder"] ...

Would resolve a to http://mydomain/vroot/uploads/... etc.将解析为http://mydomain/vroot/uploads/...等。

As an aside, note also that @"\\\\" would result in a double backslash, which I don't think you intended.顺便说一句,还要注意@"\\\\"会导致双反斜杠,我认为您不是故意的。

Either of @"\\" or "\\\\" would result in a single backslash. @"\\""\\\\"中的任何一个都会产生一个反斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM