当前位置: 代码迷 >> ASP.NET >> 从客户端删除服务器端的文件出错,怎么解决
  详细解决方案

从客户端删除服务器端的文件出错,怎么解决

热度:6212   发布时间:2013-02-26 00:00:00.0
从客户端删除服务器端的文件出错,如何解决?
以下代码是实现从客户端删除服务器端的文件的,在单机上(客户端与服务器均为同一电脑)测试没问题,但将其移到服务器上就出错,如何解决?谢谢!

protected   void   Button3_Click(object   sender,   EventArgs   e)
        {
                //先找到文件所在路径,然后判断文件存在否,最后删除文件
                string   Url= "/files/2006年/工地检查通知及通报/07年1月份实情汇报.doc ";
                string   fileUrl   =   Server.MapPath( ". ")   +   Url;
                if   (File.Exists(fileUrl))
                {   File.Delete(fileUrl);   }   //删除文件
                else
                {   Response.Write( " <script> alert( '文件不存在! ') </script> ");   }
            }


--------------------------------------------------------------

Server   Error   in   '/showbaobiao '   Application.
--------------------------------------------------------------------------------

Access   to   the   path   'e:\myweb\showbaobiao\files\2006年\工地检查通知及通报\07年1月份实情汇报.doc '   is   denied.  
Description:   An   unhandled   exception   occurred   during   the   execution   of   the   current   web   request.   Please   review   the   stack   trace   for   more   information   about   the   error   and   where   it   originated   in   the   code.  

Exception   Details:   System.UnauthorizedAccessException:   Access   to   the   path   'e:\myweb\showbaobiao\files\2006年\工地检查通知及通报\07年1月份实情汇报.doc '   is   denied.  

ASP.NET   is   not   authorized   to   access   the   requested   resource.   Consider   granting   access   rights   to   the   resource   to   the   ASP.NET   request   identity.   ASP.NET   has   a   base   process   identity   (typically   {MACHINE}\ASPNET   on   IIS   5   or   Network   Service   on   IIS   6)   that   is   used   if   the   application   is   not   impersonating.   If   the   application   is   impersonating   via   <identity   impersonate= "true "/> ,   the   identity   will   be   the   anonymous   user   (typically   IUSR_MACHINENAME)   or   the   authenticated   request   user.  

To   grant   ASP.NET   access   to   a   file,   right-click   the   file   in   Explorer,   choose   "Properties "   and   select   the   Security   tab.   Click   "Add "   to   add   the   appropriate   user   or   group.   Highlight   the   ASP.NET   account,   and   check   the   boxes   for   the   desired   access.

Source   Error:  


Line   224:                 string   fileUrl   =   Server.MapPath( ". ")   +   Url;
Line   225:                 if   (File.Exists(fileUrl))
  相关解决方案