ASP.NET中的虚拟路径 [英] Virtual Path in ASP.NET

查看:39
本文介绍了ASP.NET中的虚拟路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击链接时,我正在使用我的LinkBut​​ton的代码下载文件.最近我遇到了这个问题,我需要一个虚拟路径.

I am using this code for my LinkButton to download a file when you click on it. Recently i got this problem, i need a virtual path .

我想重定向到 C:\ inetpub \ wwwroot

 string filepath = Server.MapPath("...");           
 FileInfo myfile = new FileInfo(filepath);

所以我不知道要在Server.MapPath()中放入什么,因为如果我放入/它将进入我的文件夹文档的底部,并且没有输入

So I don't know what to put in Server.MapPath() because if I put / it will go to the base of my folder documents and no In

推荐答案

如果您需要提供系统其他部分的文件,那么最好的方法是创建虚拟目录.

If you need to serve files from another part of your system then the best way to do this is to create a virtual directory.

在IIS上,右键单击您的网站,然后单击添加虚拟目录".给它起一个名字,然后将其指向任何需要的地方.例如.指向"C:\ inetpub \ wwwroot \ files"的新虚拟目录"files".

In IIS right hand click on your website, click 'Add Virtual directory'. Give it a name and point it whereever you need it to be. E.g. new virtual directory called 'files' pointing at 'C:\inetpub\wwwroot\files'.

然后,您可以在您的网站中使用

Then from within your site you can reference these files by using

/files/filename.txt<-/files/将链接到您的虚拟目录.

/files/filename.txt <- the /files/ will link to your virtual directory.

然后,您当然需要确保已正确设置权限才能读取这些文件,但我将由您自己决定.

You will then of course need to make sure you have your permissions set correctly to read these files but I will leave that up to you.

这篇关于ASP.NET中的虚拟路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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