Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

File.Exists and UNC Shares

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KittyHawk - 12 Jul 2007 21:12 GMT
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.
Juan T. Llibre - 12 Jul 2007 21:24 GMT
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.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
>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
[quoted text clipped - 7 lines]
> start. This seems like a pretty common scenario so I imagine there should be
> a quick solution.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.