一个XML文件life.xml在一个前台页面中被使用,后台程序如下:
private void Page_Load(object sender, System.EventArgs e)
{
a......
DataTable dt;
DataSet ds;
string xmlPath = AppDomain.CurrentDomain.BaseDirectory + "life.xml";
ds = new DataSet();
ds.ReadXml(xmlPath);
dt = ds.Tables[YLWriteDataRule.MovieCommend];
dl.DataBind();......
}然后另外一个后台程序对life.xml定时进行更新,程序如下,该程序和上面的程序在同一WEB中:[WebMethod]
public string CopyFile()
{
string path = HttpContext.Current.Request.PhysicalApplicationPath;
try
{
sourefile = Server.MapPath(".") + "\\temp.xml"; //temp.xml文件的内容会定时更新
destfile = Server.MapPath(".") + "\\life.xml";
File.Copy(sourefile , destfiel , true);
return "fiel copy succeeded。";
}
catch(Exception ex)
{
return ex.Message;
}
}现在的问题是,当执行File.Copy(sourefile , destfiel , true)时,说文件life.xml没有访问权限。但是如果我进行下面2中测试,却可以拷贝,第1种测试案例是:
destfile = Server.MapPath(".") + "\\life_111.xml";
File.Copy(sourefile , destfiel , true);
这样可以执行成功,原因是不是life.xml在前台网页中有很多用户在不断调用,而life_111.xml是没有人使用的。
是这样吗?第1种测试案例是,我写了个控制台程序,如下,其中d:\webpub\是网站的发布路径:
using System;
using System.IO;
namespace fc
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string path = "d:\\webpub\\temp.xml";
string path2 = "d:\\webpub\\life.xml";
try
{
File.Copy(path, path2, true);
Console.WriteLine("The Copy operation succeeded, which was expected.");
}
catch
{
Console.WriteLine("The copy is not allowed, which was not expected.");
}
}
}
}
在这种方式下,可以把temp.xml拷贝到life.xml。所以总结一下,现在情况是:
在WEB程序中,因为life.xml被前面页面在调用,所有不能把temp.xml拷贝到life.xml中,但可以把temp.xml拷贝到没有被前台页面使用的life_111.xml文件中。但是如果不在WEB程序中,直接写一个控制台程序,却可以把temp.xml拷贝到life.xml中,虽然这是life.xml依然在被网站页面使用。需要解决的问题是:怎么在在WEB程序中,能把temp.xml更新到life.xml中。
private void Page_Load(object sender, System.EventArgs e)
{
a......
DataTable dt;
DataSet ds;
string xmlPath = AppDomain.CurrentDomain.BaseDirectory + "life.xml";
ds = new DataSet();
ds.ReadXml(xmlPath);
dt = ds.Tables[YLWriteDataRule.MovieCommend];
dl.DataBind();......
}然后另外一个后台程序对life.xml定时进行更新,程序如下,该程序和上面的程序在同一WEB中:[WebMethod]
public string CopyFile()
{
string path = HttpContext.Current.Request.PhysicalApplicationPath;
try
{
sourefile = Server.MapPath(".") + "\\temp.xml"; //temp.xml文件的内容会定时更新
destfile = Server.MapPath(".") + "\\life.xml";
File.Copy(sourefile , destfiel , true);
return "fiel copy succeeded。";
}
catch(Exception ex)
{
return ex.Message;
}
}现在的问题是,当执行File.Copy(sourefile , destfiel , true)时,说文件life.xml没有访问权限。但是如果我进行下面2中测试,却可以拷贝,第1种测试案例是:
destfile = Server.MapPath(".") + "\\life_111.xml";
File.Copy(sourefile , destfiel , true);
这样可以执行成功,原因是不是life.xml在前台网页中有很多用户在不断调用,而life_111.xml是没有人使用的。
是这样吗?第1种测试案例是,我写了个控制台程序,如下,其中d:\webpub\是网站的发布路径:
using System;
using System.IO;
namespace fc
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string path = "d:\\webpub\\temp.xml";
string path2 = "d:\\webpub\\life.xml";
try
{
File.Copy(path, path2, true);
Console.WriteLine("The Copy operation succeeded, which was expected.");
}
catch
{
Console.WriteLine("The copy is not allowed, which was not expected.");
}
}
}
}
在这种方式下,可以把temp.xml拷贝到life.xml。所以总结一下,现在情况是:
在WEB程序中,因为life.xml被前面页面在调用,所有不能把temp.xml拷贝到life.xml中,但可以把temp.xml拷贝到没有被前台页面使用的life_111.xml文件中。但是如果不在WEB程序中,直接写一个控制台程序,却可以把temp.xml拷贝到life.xml中,虽然这是life.xml依然在被网站页面使用。需要解决的问题是:怎么在在WEB程序中,能把temp.xml更新到life.xml中。
解决方案 »
- 请教权限的问题。。。
- 两个listbox,点击按钮将左边选中的插入到右边,点击另一个按钮又把右边的删除,然后点击第三个按钮取出第二个listbox的值
- 在aspx页面嵌入播放器,中文路径问题啊
- vs2005中如何修改asp.net控件访问修饰符
- 存储过程关键字的问题,关键字组,如“123,456,789”我如何分别获取123 456 789呢
- asp.net聊天室刷新问题
- 怎么隐藏datagrid的某一列?
- 那位有用jmail接受附件,并显示附件的例子?
- asp.net 显示¥符号
- 有关sql语句的问题,插入非法字符出错,请高手指教
- 大虾们,小弟跪求一个可以验证日期时间的正则表达式!!!!
- asp.net2.0写的RSS新闻聚合程序问题
但这样是不是对网站不安全啊?