Network file UNC Access from Web Application

M

mcrose

I couldn't find anything that quite described this in whole, so I'm
going to post it since from what I can tell about 400 other people have
posted asking how to do this and received partial answers

To set up an IIS 6.0 application that can access a UNC drive.

1. Create/Identify a domain account with access to the required UNC
location
2. Add that user to the IIS_WPG group on the Web Server
3. Create an application pool on the Web Server
4. Right click the new application pool and Select Properties
Select the Identity Tab
Select Configurable radio button
Enter the Account from step 1 above
5. Create a Virtual directory pointing to the application and allow
script execution.
6. Right click the Virtual Directory and Select Properties.
7. On the Virtual Directory tab of the properties dialog, select the
Application Pool created above in the Application Pool drop down


Here is the aspx and the aspx.vb for a simple application that will
list the contents of any UNC (any UNC that the application pool
identity has read access)


Default.aspx_____________________________________________________________________
<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lbError" Visible = "false" runat="server"/>
<br />
<asp:Label >UNC to display:</asp:Label><asp:TextBox
ID="TextBox1" runat="server" Width="356px"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="List contents of
UNC" /><br />
<asp:Table ID="Table1" runat="server">
</asp:Table>

</div>
</form>
</body>
</html>

Default.aspx.vb________________________________________________________________
Imports System.IO
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
For Each dirname As String In
Directory.GetFileSystemEntries(TextBox1.Text)
Dim tCell As TableCell = New TableCell
tCell.Text = dirname
Dim tRow As TableRow = New TableRow()
tRow.Cells.Add(tCell)
Table1.Rows.Add(tRow)
Next
Catch ex As Exception
lbError.Text = ex.Message
lbError.Visible = True
Finally
End Try
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top