ASP.NET Core sample app showing how to use Steeltoe to manage credentialed connections with Windows file shares.
- Windows machine with the .NET 8 SDK installed
- Pre-existing Windows file share or local adminstrator rights
- Optional: Tanzu Platform for Cloud Foundry with Windows support
Before running the app, you need to create the fileshare or update appsettings.Development.json
with the values for a pre-existing fileshare.
Caution
The script add-user-and-share.ps1 must be run as administrator, in Windows. As with any script found on the internet, review the contents before running it.
- Open a PowerShell window as an administrator
cd
to thescripts
directory- Run add-user-and-share.ps1, optionally using parameters to override the default values:
-ShareName steeltoe_network_share
- the name of the share-SharePath c:\steeltoe_network_share
- the path to the share-UserName shareWriteUser
- the name of the user-Password thisIs1Pass!
- the password for the user
- Open the
appsettings.Development.json
file - Update the
location
,username
, andpassword
values with the appropriate values for your file share - Save the file
- Open a terminal window
cd
to thesrc\FileSharesWeb
directory- Run the app with the following command:
dotnet run --launch-profile https
Once the app is running, you should be able to upload files and list files in the file share. Multiple files can be uploaded at once using the form provided, but you should be aware that files are renamed when they are saved in order to prevent issues with improper characters. You can also delete files by clicking the "Delete file" button in the same row as the file name on the list files page.
Tip
The sample uses credentials different from those of your Windows user account. If you've opened the file share in Windows Explorer before running the sample, it fails because a file share can't be accessed by one user using multiple credentials. To recover, run klist purge
to make Windows forget the connection from Windows Explorer.
Caution
The script remove-user-and-share.ps1 must be run as administrator, in Windows. As with any script found on the internet, review the contents before running it.
When you are done working with the sample, you can remove the user account, the file share, and its target directory, with the following steps:
- Open a PowerShell window as an administrator
cd
to thescripts
directory- Run remove-user-and-share.ps1, optionally using parameters to override the default values:
-ShareName steeltoe_network_share
- the name of the share-SharePath c:\steeltoe_network_share
- the path to the share-UserName shareWriteUser
- the name of the user
Before deploying the app, you must create an entry in CredHub to contain the credentials.
- Run cf-create-service.ps1 to create a service instance in CredHub, using parameters to set the required values:
-NetworkAddress \\\\<hostname>\\<sharename>
- escaped UNC path of the fileshare-UserName <username>
- the username for accessing the fileshare-Password <password>
- the password for accessing the fileshare
- This sample will only run on Windows, so binaries must be built locally before push. Use the following commands to publish and push the app:
dotnet publish -r win-x64 --self-contained cf push -f manifest-windows.yml -p bin/Release/net8.0/win-x64/publish
- Copy the value of
routes
in the output and open in your browser
See the Official Steeltoe Windows Network File Shares Documentation for more detailed information.