File.Exists and UNC Shares

G

Guest

I am trying to use the File.Exists method on image files that are located in
a virtual directory on a UNC share from IIS6. The UNC share is located on a
Windows 2000 Server machine.

I can view the files just file over HTTP on the IIS server. However, when I
use File.Exists it always returns False. Of course I am using server.mappath
with File.Exists.

I am pretty sure this is a permissions issue but I'm not sure where to
start. This seems like a pretty common scenario so I imagine there should be
a quick solution.
 
J

Juan T. Llibre

Does the account which ASP.NET is running as
have read permissions to the UNC share ?

If not, give that account permission to read the share,
and watch as everything works fine.

You may need to create a domain account and
run ASP.NET as that account ( impersonattion ).

If you don't know which account ASP.NET is running as,
copy the following code as "identity.aspx",and run it:

identity.aspx:
-------------------
<%@ Page Language="VB" %>
<%@ Import NameSpace = System.Security.Principal %>
<script runat="server">
Sub Page_Load()
Dim tmp As String = WindowsIdentity.GetCurrent.Name()
Label1.Text = "ASP.NET is running as the account : " & tmp
End Sub
</script>
<html>
<head>
<title>What account is ASP.NET running as ?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
------------

Running that script will tell you the account ASP.NET is running as.
Giving that account permission to access the UNC share will solve your problem.

Howeve, if you're running ASP.NET as a local account ( ASPNET or NETWORK SERVICE ),
you will not be able to give that local account permission to access the UNC share
( because that account will not exist in the server where the share is located ).

If that's the case, you will need to create a domain account to run ASP.NET as,
impersonate ASP.NET using that acount, and give permission to access the share
to the same account.
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top