0

I am new with ASP.NET and MVC2 and I am wondering how can I determine if a user has traversed through one of my web application folders. For example, the URL in the address bar is

localhost:some numbers/Images/Others/model1.jpg

and the page displays the image. Instead of displaying the image, I want to close or block the page (if that is possible).

(Please edit this if necessary if my terminology is wrong.)

Finally, note that I tried HttpContext.Current.Request.Url and Request.ServerVariables["URL"] but neither returns want I want.

DavidRR
  • 18,291
  • 25
  • 109
  • 191
gibz357
  • 235
  • 1
  • 7
  • 20
  • Are you trying to determine if someone CAN access an image, or if someone HAS accessed an image? – Tieson T. Aug 30 '12 at 02:45
  • @Tieson If some has accessed the image. From above, user has gone to this URL "localhost:some numbers/Images/Others/model1.jpg" – gibz357 Aug 30 '12 at 02:47

2 Answers2

0

There isn't any straight forward method but I've used handlers/modules and loaded the css/Javascript dynamically.

KV Prajapati
  • 93,659
  • 19
  • 148
  • 186
0

Are you looking for a way to handle requests to all (or maybe just *.jpg) files including static files?

To handle requests to existing files in the code you need to following:

  • runAllManagedModulesForAllRequests in Web.Config to let IIS forward requests to your code instead of serving static content first (i.e. check this article)

To server content - return FileResult from your handler. Usually done by using File helper method of Controller. See this question: Can an ASP.NET MVC controller return an Image?

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179