access denied error with response.writefile of UNC file in IIS7. Bug?

probably i'm in the wrong place, but there's not a place.

I'm moving applications from IIS6 to IIS7.5 (win 7 an win server 2008 r2), when 2 applications (with identity impersonate) try to get a file with response.writefile only from a UNC path i'll get "access denied". In IIS6 and Visual Studio Developer Web Server, same code works.

I can save file with FilePath.SaveAs and get name and length with FileInfo, but not download.

After 2 days of nightmares I have tried to change

Response.WriteFile(filePath) 

to

Response.BinaryWrite(File.ReadAllBytes(filePath))

and now work.

My question is: can I have a microsoft developer to sacrificate for my avenge ????? :)

    • Re: access denied error with response.writefile of UNC file in IIS7. Bug?

      03-09-2010, 12:37 AM
      Answer

      Hi,

      I test "Response.WriteFile" with my IIS7.5 server and write the file with UNC path. But I did not get your error. Maybe it is a configuration mistake for you. Here I post my steps for the testing demo.

      Step 1, Add a ASP.NET Website or ASP.NET Web Application, and create an empty page. The markups in "default.aspx" leave it default, the codes in "default.aspx.cs" are wriiten as below.

      1. public partial class _Default : System.Web.UI.Page   
      2.     {   
      3.         protected void Page_Load(object sender, EventArgs e)   
      4.         {   
      5.             Response.WriteFile("jerrywengpc//TDdownload//abc.txt");   
      6.         }   
      7.     }  

      Step 2, Modify the web.config for ASP.NET 4.0.

      1. <configuration>  
      2.   <connectionStrings />  
      3.   
      4.   <system.web>  
      5.     <compilation debug="true" targetFramework="4.0" />  
      6.   
      7.     <authentication mode="Windows">  
      8.     </authentication>  
      9.     <pages controlRenderingCompatibilityVersion="3.5"></pages>  
      10.     <customErrors mode="Off"/>  
      11.   
      12.   </system.web>  
      13.   
      14.   <system.webServer>  
      15.       
      16.   </system.webServer>  
      17. </configuration>  
      <configuration>
        <connectionStrings />
      
        <system.web>
          <compilation debug="true" targetFramework="4.0" />
      
          <authentication mode="Windows">
          </authentication>
          <pages controlRenderingCompatibilityVersion="3.5"></pages>
          <customErrors mode="Off"/>
      
        </system.web>
      
        <system.webServer>
         
        </system.webServer>
      </configuration>


      Step 3, Publish the web application or web site to one directory on your server.

      Step 4, Create a web site and deploy your application there.

      Step 5, Use ASP.NET IIS Registration Tool (Aspnet_regiis.exe), and run this line with it:

                             aspnet_regiis.exe -r

      Step 6, Test your site.

      Jerry Weng - MSFT

      Please mark the replies as answers if they help or unmark if not.
      Feedback to us
      Microsoft One Code Framework
    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值