ASP.NET Core sample app showing how to use Steeltoe to manage credentialed connections with Windows file shares.
- Windows machine with the .NET 10 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
cdto thescriptsdirectory- 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.jsonfile - Update the
location,username, andpasswordvalues with the appropriate values for your file share - Save the file
- Open a terminal window
cdto thesrc\FileSharesWebdirectory- 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
cdto thescriptsdirectory- 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.
Note
The cf-create-service.ps1 script requires PowerShell 7 or later.
- Run cf-create-service.ps1 to create a service instance in CredHub, using parameters to set the required values:
-NetworkAddress \\<hostname>\<sharename>- UNC path to the network share (required). For example:\\localhost\steeltoe_network_share-UserName <username>- the username for accessing the file share, can include domain (e.g.,DOMAIN\username) (required)-Password <password>- the password for accessing the file share (required)-ServiceName credhub- the name of the service for storing credentials-ServicePlan default- the service plan to use-ServiceInstanceName sampleNetworkShare- the name of the service instance
- 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/net10.0/win-x64/publish
- Copy the value of
routesin the output and open in your browser
See the Official Steeltoe Windows Network File Shares Documentation for more detailed information.