Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.Net MVC3 app downloading files to client from another network server
    primarykey
    data
    text
    <p>We currently use the code below to download files from a network server to the client in an old ASP.net page. </p> <p>We have re-written the app in MVC3 and would like to upgrade this functionality. I have seen several posts that claim you can access the file from the network share by writing the following lines in web.config</p> <pre><code>&lt;authentication mode="Windows"/&gt; &lt;identity impersonate="true" userName="" password="" /&gt; </code></pre> <p>However, we are currently using Forms authentication mode to logon to the site. Would that interfere with the login functionality?</p> <p>Here's our download code.</p> <pre><code>Partial Class DownloadFile2 Inherits System.Web.UI.Page Private BufferSize As Integer = 32 * 1024 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim path As String = Request.Params("File") path = "\\speedy\wanfiles\" + path.Substring(3) Dim file As System.IO.FileInfo = New System.IO.FileInfo(path) Dim Buffer(BufferSize) As Byte Dim SizeWritten, fileindex As Integer Response.Clear() Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name) Response.AddHeader("Content-Length", file.Length.ToString) Response.ContentType = "application/octet-type" Response.Flush() fileindex = 0 Do // not sure about this GM.AlasData code below SizeWritten = GM.AlasData.ReadFileBlock(file.FullName, Buffer, fileindex, BufferSize) Response.OutputStream.Write(Buffer, 0, SizeWritten) Response.Flush() If SizeWritten &lt; BufferSize Then Exit Do Else fileindex = fileindex + SizeWritten End If Loop Response.End() End Sub End Class </code></pre> <p>I found this code to do downloads using MVC3 but cannot access the file because it is considered a local file.</p> <pre><code>public FileResult Download(string FilePath) { if (FilePath != null) { string path = FilePath; string contentType; // files are stored on network server named speedy path = string.Concat(@"\\speedy\files\", HttpUtility.UrlDecode(path)); System.IO.FileInfo file = new System.IO.FileInfo(path); Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(file.Extension.ToLower()); if (rk != null &amp;&amp; rk.GetValue("Content Type") != null) { contentType = rk.GetValue("Content Type").ToString(); } else { contentType = "application/octet-type"; } //Parameters to file are //1. The File Path on the File Server //2. The content type MIME type //3. The parameter for the file save by the browser return File(file.FullName, contentType, file.Name); } else { return null; } } </code></pre> <p>What needs to be done to fix this where we can perform this functionality?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload