So i have a server A and server B.
Server A: Windows Server 2008R2 Server B: Windows Server 2003
Web page is using framework 4.0, created with VS2013 Pro RC
on server A my asp.net/c# webpage is running on IIS7 on server B i have a shared folder.
Now i have mapped this shared folder from server B to server A, and its fully accessible via the Desktop\Windows Explorer, however accessing the folder from the webpage is a different story.
To access the folder, what i have done in IIS7 is, create a virtual folder under the same webpage, and point it to the mapped drive.
This would of course have worked if the folder would have been on the same server A, but since it's on a different server B, i get the following error.
Could not find a part of the path 'L:\a\b\file.pdf' now the path is 100% correct, since i have checked.
Heres some additional debug info:
Could not find a part of the path 'L:\a\b\file.pdf'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'L:\a\b\file.pdf'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path 'L:\a\b\file.pdf'.] System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +216 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath) +2481 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +229
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +102
System.Web.HttpResponse.WriteFile(String filename, Boolean readIntoMemory) +166 Reloc.Client.Contracts.openLinkClick(Object sender, EventArgs e) in c:\Users\x\Documents\Visual Studio 2013\Projects\p\p\S\Listdoc.aspx.cs:230
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +1192
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +164 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
I beleive this might have something to do with permission or related, have tried numerous thing, without luck. So please help me out here. Thanks in advance.
Right-click the Web site that you want (for example, Default Web Site), point to New, and then click Virtual Directory. On the Welcome to the Virtual Directory Creation Wizard page, click Next. On the Virtual Directory Alias page, type the alias that you want (for example, Sales), and then click Next.
How to access network drive from outside network? Using a VPN is the best way to access a network drive. Accessing a mapped network drive from outside your network can be done by typing the IP address of the remote computer in the search bar. A popup showing the shared info should open if the drive is mapped properly.
As wata suggests, each user gets their own mapped drives. This means that your L: drive is not the same as your app pool account's L: drive.
In addition, unless you've changed the account your app pool is running as, it won't be able to access the shared folder on the other server. Most likely you're logging in to both servers using an Active Directory domain account. If so, you will probably want to create a new Active Directory domain account to use as the identity for your app pool. You could change the app pool identity to use your own domain account for dev/testing purposes, but that's not a recommended security practice in a production system.
Once you've created the new Active Directory "service account" (to avoid future hassle, make sure the password doesn't expire), you'll want to change your app pool's identity in IIS. Go to Application Pools, find the app pool in use by your site, select it and choose Advanced Settings on the right, go to Identity, and click the ... button to set the custom account, making sure to prefix the username with the domain name: mydomain\myserviceusername.
You'll also want to grant your service account access to Server B's share.
Now you will need to create a persistent mapped drive from Server A to Server B using your service account. See this for details, making sure to set up a script that remaps the drive after a reboot using a command such as net use L: \\ServerB\sharedfolder /persistent:yes
, making sure this is run as your service account. You could potentially even run this first thing in your app's Global.asax.cs Application_Start. If you want to avoid the hassle of the steps in this paragraph, use wata's suggestion of using the full UNC path instead of using a mapped drive.
Now your web app should be able to access the shared folder on Server B. :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With