В моем веб-приложении asp.net core 2.2, в классе Start-Up, в методе Configure я установил использование статических файлов, сопоставил указанную папку на диске, установив таким образом поставщика файлов:
FileProvider = new PhysicalFileProvider(@"C:\business\ROM\documents\112233\")
как в этом коде:
используя ...
namespace MyApp
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>()
.AddDefaultUI(UIFramework.Bootstrap4)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(@"C:\business\ROM\documents\112233\"),
RequestPath = new PathString("/dexml")
});
app.UseCookiePolicy();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
Когда я перечисляю свои натуры, в цикле foreach в представлении я связываю документы следующим образом:
<a target="_blank" href="/dexml/@Html.DisplayFor(modelItem => item.nomefile)">view document</a>
Все отлично работает!
Но мне нужно установить корень строки PhisicalFileProvider с заполнителем, как это:
FileProvider = new PhysicalFileProvider(@"C:\business\[code1]\documents\[code2]\")
и я связал code1 и code2 в пользовательских полях идентификации пользователя asp.net.
Как я могу установить корень строки FileProvider с заполнителем и заменить его там же с пользовательскими атрибутами?
спасибо