Last active
May 16, 2021 21:53
-
-
Save manoj-choudhari-git/53a96467d07113a2677fdf9a32be0eba to your computer and use it in GitHub Desktop.
.NET Core Web Applications - Static Files - Serve Files from Network Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Startup | |
{ | |
// some other code... | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
else | |
{ | |
app.UseExceptionHandler("/Home/Error"); | |
app.UseHsts(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseStaticFiles(); | |
// HARDCODING FOR DEMO ONLY - Use either Azure Key Vault or some other secret manager | |
var sourceCredentials = | |
new NetworkCredential { Domain = "domain", UserName = "user", Password = "pass" }; | |
using (new NetworkConnection("\\\\Network\\Shared", sourceCredentials)) | |
{ | |
// to serve static froms from \\network\shared location | |
app.UseStaticFiles(new StaticFileOptions() | |
{ | |
FileProvider = new PhysicalFileProvider( | |
Path.Combine("\\\\Network\\Shared")) | |
}); | |
} | |
app.UseAuthorization(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllerRoute( | |
name: "default", | |
pattern: "{controller=Home}/{action=Index}/{id?}"); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment