Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Last active May 16, 2021 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/53a96467d07113a2677fdf9a32be0eba to your computer and use it in GitHub Desktop.
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
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