简体   繁体   English

StreamReader Server.MapPath-给定的物理路径,预期的虚拟路径

[英]StreamReader Server.MapPath - Physical path given, virtual path expected

Im trying to get my .Net website to read the first line in a text file that shows a status of the computer it is located on. 我试图让我的.Net网站读取文本文件中的第一行,该文件显示了其所在计算机的状态。 I get the good old "Server.MapPath - Physical path given, virtual path expected" if I remove the Server.MapPath, it fixes it the problem on the server, but then errors on the clients computer because it seems to be trying to access the file on the clients PC. 如果删除Server.MapPath,我会得到很好的旧版“ Server.MapPath-给定的物理路径,需要虚拟路径”,它可以解决服务器上的问题,但是由于似乎正在尝试访问而导致客户端计算机上的错误客户端PC上的文件。 Here is snippet: 这是代码段:

        StreamReader StreamReader3 = new StreamReader(Server.MapPath(@"C:\\status\\status.txt"));
        TextBox2.Text = StreamReader3.ReadLine();
        StreamReader3.Close()

I know I probably could fix the issue by moving the file called to the same folder as the webpage, and have my server side program update the file there, but is there a way to do this otherwise? 我知道我可能可以通过将调用的文件移到与网页相同的文件夹中来解决此问题,并让我的服务器端程序在那里更新文件,但是是否可以通过其他方式做到这一点? Thanks. 谢谢。

MapPath translates paths starting from ~ to full local path. MapPath会将路径从〜转换为完整的本地路径。 Does not look like you need it in your code. 看起来您的代码中似乎不需要它。

If the file is supposed to be at fixed place all the time, open in directly by full path. 如果文件应该一直放在固定位置,请直接用完整路径打开。

If it is relative to site root, then use something like Server.MapPath("~/status.txt") 如果相对于站点根目录,则使用类似Server.MapPath(“〜/ status.txt”)的名称。

暂无
暂无

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

相关问题 Server.MapPath - 给定的物理路径,预期的虚拟路径 - Server.MapPath - Physical path given, virtual path expected c# - 给定物理路径,Server.MapPath 中需要虚拟路径 - c# - Physical path given, virtual path expected in Server.MapPath Server.MapPath不会返回映射到Web-App子文件夹中的虚拟目录的正确物理路径 - Server.MapPath does not return the right physical path mapped to a virtual directory in Web-App subfolder Server.MapPath(virtualPath)返回控制器的根目录,也不返回IIS中虚拟目录中提到的物理路径 - Server.MapPath(virtualPath) Returns root directory of controller, it is nor returns the physical path mentioned in the virtual directory in IIS 使用server.MapPath()时不允许使用相对虚拟路径 - Relative virtual path is not allowed when using server.MapPath() Server.MapPath给出了错误的路径,在IIS服务器上运行时出现异常“不支持给定路径的格式”? - Server.MapPath gives wrong path, exception “The given path's format is not supported” when running on IIS server? 使用Server.MapPath()时如何从虚拟路径中排除控制器名称? - How can I exclude controller name from the virtual path when I use Server.MapPath()? c#使用Server.MapPath()找不到路径的一部分 - c# Could not find a part of the path with Server.MapPath() Server.MapPath()返回与DirectoryInfo一起使用时不存在的路径 - Server.MapPath() returning a path that does not exist when used with DirectoryInfo server.mappath 将引用的文件路径解析为相对目录 - server.mappath resolve referenced file path to relative dir
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM