Disclaimer: I am a consultant at Amazon Web Services, and this is my personal blog. The opinions expressed here are solely mine and do not reflect the views of Amazon Web Services (AWS). Any statements made should not be considered official endorsements or statements by AWS.
If you are running a .NET Core application in a Linux container and want to access Windows Share (Network Share) that is secured with credentials, then you can use the below C# based solution.
Step 1: Install the CIFS utility in the container through the docker file.
Write this command just before we call entry point ENTRYPOINT ["dotnet", "NETCoreApp.dll"]
Step 2: Add below class NetworkDriveUtility
in your project and replace the below 4 variables with their actual values:
Step 3: Call the MountNetworkDrive
method in the Main
method.
That's it. If the success
variable's value is true then you are done.
Mount Verification - I am verifying by creating a text file on the share path and checking if file gets created or not. If created, then we consider that drive mounted successfully and delete the file in the next step.
Hope this should solve your purpose. 😊