asp.net serving static files

3

I have an application in mvc3 (asp.net 4.0, dotnet 4.0), running on iis8 (but it's also running on iis 7 and iis 7.5).

Within the application I have a folder called /dados example localhost/minhaapp/dados .

My clients save HTML files within this folder, and these HTML files are accessed by the system made in mvc3.

But users are accessing the files directly through the URL of the browser, example localhost/minhaapp/dados/relatorio1.html , instead to access an internal system option made in mvc3.

  • Can you block GET method access from the HTML files of /dados ?

But I want the system made in mvc3 to be able to access these files via POST method. This is not the safest method, there must be many other possibilities, but if it does it would be fine.

I have tried various forms, rewrite, modules, urlmapping, mvc controler, etc., but neither of these forms captures the browser's request for static files. I know that static files are served directly by iis.

  • But is there any way for ASP.NET to intercept static file requests?

  • If it is not possible via ASP.NET, have some configuration that works on iss 8, 7.5 r 7?

I can not change to another folder, nor save the files in another way, that is, internal policies (the fact that this is already the case and is very widespread and used by multiple clients), how and where files are saved, It can not be changed.

    
asked by anonymous 13.01.2015 / 18:02

3 answers

3

You tell the ISS that every request must pass through it. IIS does not apply permission on static files.

In your Web.config put the following code:

<configuration>
    ...
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
    ...
</configuration>
    
13.01.2015 / 18:21
2

I was able to run, put runAllManagedModulesForAllRequests="true", changed the application pool to integrated mode, and put the BegingRequest method in global.asax, I restarted the application, and now it captures all requests.     

14.01.2015 / 16:57
1

As I have already answered here, this is the way incorrect to make static files available in your application .

Can you block GET method access from the folder / data HTML files?

Yes, creating an Index method to prevent access to the root, or an empty % file.

But is there any way for ASP.NET to intercept (sic) static file requests (sic)?

Tem. You just need to make a method on your Controller that returns a index.html .

In addition, it is good to define a route that always redirects to FileResult , in case your user tries to access the file directly:

App_Start / RouteConfig.cs

routes.MapRoute(
            name: "Dados",
            url: "dados/{id}",
            defaults: new { controller = "Dados", action = "Index", id = UrlParameter.Optional }
        );
    
13.01.2015 / 19:24