gpt4 book ai didi

c# - ASP.NET MVC : converting virtualpath to actualpath is wrong

转载 作者:太空宇宙 更新时间:2023-11-03 18:18:49 28 4
gpt4 key购买 nike

我一直在使用 Url.Content inside <% and %> in my views and all seems to work fine... 然后从我的 Controller 中我尝试了以下,但它总是返回错误的路径

 XDocument xdoc = XDocument.Load(Url.Content("~/content/xml/faq.xml"));

 XDocument xdoc = XDocument.Load(VirtualPathUtility.ToAbsolute("~/content/xml/faq.xml"));

基本上路径应该是c:\Vs2008\Source\MyAppName.....

但它返回 c:\MyAppName.....

所以它是无效的,

知道为什么会这样吗??有变通办法吗?

最佳答案

这两种方法仅适用于客户端通过您的网络服务器访问内容的情况。要在内部读取文件,您需要在应用程序中使用 Server.MapPath() 或类似方法来获取磁盘上的物理路径。

关于c# - ASP.NET MVC : converting virtualpath to actualpath is wrong,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1907986/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com