Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Prevent users from directly accessing files inside our asp.net MVC core web application

$
0
0

I have 2 excel sheets inside my Asp.net core MVC web application under a folder named "Files" as follow:-

enter image description here

Where i am referencing these files inside my TextFieldParser method as follow:-

public class HomeController : Controller
{
    protected IWebHostEnvironment _host; // using Microsoft.AspNetCore.Hosting

    public HomeController(IWebHostEnvironment webHostEnvironment)
    {
        _host = webHostEnvironment;
    }

    public IActionResult Index()
    {
        string YOURCURRENTFILE = _host.ContentRootPath + @"/Files/v2.csv";
using (TextFieldParser parser = new TextFieldParser(YOURCURRENTFILE ))
{ // USE YOUR TextFieldParser logic } }

inside my startup.cs i have the following app.UseStaticFiles(); as follow:-

publicvoidConfigure(IApplicationBuilder app,IWebHostEnvironment env){if(env.IsDevelopment()){}else{

            app.UseStaticFiles();

so in my case can users directly access the files? or they can only access them through my action methods?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>