孟子,思归请进来看看!一个跨服务器读取文件,很难搞且大家都有可能碰到的问题。
环境:
我有两台服务器:A、B服器
1、首先在B服器上共享一个文件夹为share;
2、其次在A服器上用映射的方式,创建一个G:盘;
3、接着写一个程序读取G:盘里的文件名;
4、在A服器上建一个站点,将其发布;
问题:
1、通过IIS发部布的站点访问,就会出现在无法找到G盘的错误提示;
2、如果是在VS2005上直接调试,不会出现在问题;
我试过的方法:
我估计是由于IIS的权限不够才会出现这种问题,可郁闷的是我试了N种法,都没有能搞定,所以才来求助高手!(分数不是问题,不够再加!)
程序:
string m_strPhysicsPath = "g:/ ";
protected void Button1_Click(object sender, EventArgs e)
{
string currentdir = m_strPhysicsPath; //搜索的目录
if (currentdir[currentdir.Length - 1] != '\\ ') //非根目录
currentdir += "\\ ";
DataTable Dt = FineFistTable(currentdir);
GridView1.DataSource = Dt;
GridView1.DataBind();
}
protected DataTable FineFistTable(string m_strPath)
{
DirectoryInfo Dir = new DirectoryInfo(m_strPath);
DataTable Dt = new DataTable();
Dt.Columns.Add( "FileName ");
Dt.Columns.Add( "FileSize ");
Dt.Columns.Add( "CreatTime ");
string[] FolderArry = Directory.GetDirectories(m_strPath);
foreach (string FolderName in FolderArry)
{
DataRow dr = Dt.NewRow();
dr[ "FileName "] = FolderName;
Dt.Rows.Add(dr);
}
foreach (FileInfo FileName in Dir.GetFiles( "*.* "))
{
double i = double.Parse(FileName.Length.ToString());
i = i / 1024;
DataRow Dr = Dt.NewRow();
Dr[ "FileName "] = m_strPath + FileName.ToString();
Dr[ "FileSize "] = i.ToString( "0.0 ");
Dr[ "CreatTime "] = FileName.CreationTime.ToString();
Dt.Rows.Add(Dr);
}
return Dt;
}
//返回到上一层
protected void Button2_Click(object sender, EventArgs e)
{
m_strPhysicsPath = m_strPhysicsPath.Substring(0, m_strPhysicsPath.Length - m_strPhysicsPath.LastIndexOf( "/ "));
DataTable Dt = FineFistTable(m_strPhysicsPath);
GridView1.DataSource = Dt;
GridView1.DataBind();
}
[解决办法]
在A,B上建两个用户,相同的用户名,相同的密码.这个用户对B这个文件夹有写的权限.在A的web.config中启用身份模拟,模拟帐号就用这个新建的帐号
[解决办法]
用WEBSERVICE上传下载
http://dotnet.aspx.cc/article/6381bd5f-51f3-4339-4239-1328564a1b2a/read.aspx
[解决办法]
帮顶兼学习~
[解决办法]
实在不行,就把要读写的服务做共享,然后给写的权限
再在G盘给.net的权限
我是这样搞的,不过,我想有问题,呵呵!