抛出的异常“'h:/Dictionary.txt'是物理路径,但是应该是虚拟路径." [英] Exception thrown "'h:/Dictionary.txt' is a physical path, but a virtual path was expected."

查看:59
本文介绍了抛出的异常“'h:/Dictionary.txt'是物理路径,但是应该是虚拟路径."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过以下代码获取上述问题:confused:

Getting the above issue in the below code:confused:

Cache.Insert("FileCache", File.ReadAllText(@"h:\Dictionary.txt"), new CacheDependency(Server.MapPath(@"h:\Dictionary.txt")));



请帮助:doh:

将内联代码转换为代码块; 忽略文本中的HTML"选项已关闭-OriginalGriff [/edit]



Please help :doh:

[edit]inline code converted to code block; "ignore HTML in text" option turned off - OriginalGriff[/edit]

推荐答案

这是您的问题
CacheDependency(Server.MapPath(@"h:\Dictionary.txt")));

Server.MapPath采用虚拟路径,并为您将其转换为物理路径.但是您给它一个物理路径,即"h:\Dictionary.txt"

试试这个
CacheDependency(@"h:\Dictionary.txt");

为了使其正常工作,您的ASP.NET需要具有对该文件夹的访问权限.您可以在属性页上的文件夹安全性选项卡中设置访问权限.
here is your issue
CacheDependency(Server.MapPath(@"h:\Dictionary.txt")));

Server.MapPath takes a virtual path and converts it to physical path for you. But you are giving it a physical path, i.e "h:\Dictionary.txt"

Try this
CacheDependency(@"h:\Dictionary.txt");

In order for this to work, you ASP.NET need to have an access to that folder. You set the access in the folder security tab on the property page.


当您的代码可以执行大量操作时,请尝试将其分为几个小步骤,例如存储返回值Server.MapPath,然后使用该变量.这样,您可以找出导致问题的原因.
When you have code that does a ton of things, try breaking it in to little steps, such as storing the return value of Server.MapPath and then using that variable. That way, you can work out which part is causing the issue.



<< code>/strike> gg

<<code>/strike>gg


这篇关于抛出的异常“'h:/Dictionary.txt'是物理路径,但是应该是虚拟路径."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆