Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.NET Core Web Applications - Static Files - Serve Files from Network Path
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