I have a file that needs to be read from. The problem is that if I have the FileStream open and read it everytime a request is made, the application becomes very very slow due to the size of the file (A few MB), and the fact that it runs on every request. Is there a way to read it from the beginning, then inside my Controller just refer to it?
This is my initialization code:
namespace WebsiteServer
{
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.AddMvc();
}
// 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();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{*url}");
});
}
}
}
Thank you!