Cannot access remote shared files in ASP.Net

Asked By 140 points N/A Posted on -
qa-featured

I have a web application that requires to read a shared Excel sheet that is hosted on a network share. This network share is located in another machine. I can manually access the network share, but when I attempt to access it via the source code, I get an "access denied" error message. Why is this and how do I fix this?

 

SHARE
Best Answer by WizKid
Answered By 0 points N/A #90785

Cannot access remote shared files in ASP.Net

qa-featured

Is the computer part of a Windows domain, then there might be a restriction imposed on who could access the machine. By default the "Guest" account is disabled. Can you check if the guest account is enabled on the remote machine? The Guest account is required to allow remote anonymous access to resources shared on the local machine. 

 

Answered By 140 points N/A #90786

Cannot access remote shared files in ASP.Net

qa-featured

The computer is not under a windows domain. We don't use a domain controller in our network. All machines are peers. I have checked regarding the Guest account. It is disabled. The IT admin says it should not be enabled as viruses could propagate if the guest account is active. Therefore I rather leave it be. There is another thing to note though. I am logged on to my machine as "Eric". But the .Net error message says access is denied for user ERICPCASPNET.

 

Answered By 0 points N/A #90788

Cannot access remote shared files in ASP.Net

qa-featured

In order to "serve" pages to the web client, each resource need to be read and accessed from the computer. In order to do this Internet Information Services need to authenticate itself to the operating system. Since it is not practical to have billions of user accounts, a common user account is used by Internet Information Services.The account used by IIS is commonly created as IUSR_MACHINENAME.

Likewise for .Net Web Applications, in order to access resources, it uses a special account called ASPNET. This user account is created when you configure IIS to run ASP.Net based applications.Your default application uses this account. You need to specify an alternate account to your website that has access both locally s well as remote access to the network share.You can do this by putting the required username and password on the IIS website instead of the default accounts.

Answered By 140 points N/A #90790

Cannot access remote shared files in ASP.Net

qa-featured

Thank you Electrica for the information. I have tried it and it worked! I put my username and password instead of the default user account in IIS. Thereafter I was able to access the remote resource. It just occurred to me that the passwords are set to expire. And it would not be good if the website goes down suddenly due to expiration of the password. Is there a way where we can do remote access via .Net without changing any IIS settings?

Answered By 0 points N/A #90793

Cannot access remote shared files in ASP.Net

qa-featured

Eric,

You have a point there. It would not be practical to be changing the user accounts in IIS every time. Besides it would not do if the website is being hosted on a shared location. I will have to check on this and get back to you!

Answered By 140 points N/A #90794

Cannot access remote shared files in ASP.Net

qa-featured

Just to help you further I am using .Net Framework 2.0. And I am using C# as the programming platform. Please see if you can advise me on a solution. I will keep watching this post! I really would like not to be changing any IIS settings. Like you rightly mentioned in a shared hosting platform it would not be practical.

 

Best Answer
Best Answer
Answered By 0 points N/A #90795

Cannot access remote shared files in ASP.Net

qa-featured

Electrica is on the right track. We need to replace the default ASPNET account with another valid account. I was digging around the .Net documentation and I think you need to make the .Net website itself impersonate a different user. You can do this by putting the following in the web configuration file. You need to replace the username and the password values to VALID accounts that is there in BOTH computers.

<system.web>
<identity impersonate="true" userName="a valid username" password="a valid password"/>
</system.web>
 
When the above code is added, the .Net framework creates a local authentication token using the given username and password. This token is then used instead of the default ASPNET account for carrying out ALL operations. It is important to note that the same credentials will be used to authenticate access to remote resources. Therefore ensure this account is created in the remote machine as well.
Answered By 140 points N/A #90796

Cannot access remote shared files in ASP.Net

qa-featured

WizKid,

You are a genius! Your suggestion worked like a charm! Furthermore if the password is changed all i need to do is to edit the web configuration file. And since the web.config file is protected and cannot be downloaded by a direct link, it is extremely secure as well.
 
Thank you.
Answered By 0 points N/A #90797

Cannot access remote shared files in ASP.Net

qa-featured

Aha yes. I believe even experts do require help! Thank you WizKid!

 

Answered By 0 points N/A #90798

Cannot access remote shared files in ASP.Net

qa-featured

Glad to be of help!

 

Related Questions