开发者

Downloading file from server for user logged in as guest

I have a code which allows you to download any file from server to your local host.

This code works fine when i log in as administrator but when i log in as guest user it does not let me download.. and i get an error message saying..

External component has thrown an exception. 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.Runtime.InteropServices.SEHException: External component has thrown an exception.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

My code is as follows

string filepath = restoredFilename.ToString();

            // Create New instance of FileInfo class to get the properties of the file being downloaded
            FileInfo myfile = new FileInfo(filepath);

            // Checking if file exists
            if (myfile.Exists)
            {

                // Clear the content of the response
                Response.ClearContent();

                // Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
                Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);

                //Response.AddHeader("Content-Disposition", "inline; filename=" + myfile.Name);
                // Add the file size into the response header
                Response.AddHeader("Content-Length", myfile.Length.ToString());

                // Set the ContentType
                Response.ContentType = ReturnExtension(myfile.Extension.ToLower());

                //// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
                Response.TransmitFile(myfile.FullName);

                // End the response
                Response.End();
            }

I have to download the file using guest.. please help thanks

Stack Trace:

[SEHException (0x80004005): External component has thrown an exception.]
   xyzgui.Guest.DriveContents.RestoreOneFileForGUI(Int32 machineID_Download, Int64 fileID, StringBuilder restoredFilename, UInt32 restoredFilenameBufsize) +0
   xyzgui.Guest.DriveContents.file开发者_如何学Go_Click(Object sender, EventArgs e) in C:\Users\jagmit\Documents\Visual Studio 2008\Projects\xyzgui\xyzgui\Guest\DriveContents.aspx.cs:341
   System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +79
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


What authentication mechanism are you using: Forms, or Windows?

Do you have impersonation turned on?

I believe that the error you are seeing is generally thrown when there's a security issue - which sounds likely when you say "when I log in as administrator".

Is there more to the method RestoreOneFileForGUI that we're not seeing - because it looks like something is throwing a security exception outside of .NET - if it was as simple as the guest account (the account the website is running under) not having access to the file path then you'd see a standard SecurityException or UnauthorizedException from the FileInfo constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜