I am developing a module for Orchard which will restrict the items in the Media folder by looking up the authenticated user permissions.
The first thing was editing the web.config in the Media folder like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="MediaFileAccess.AuthorizedMediaHandler" />
</httpHandlers>
</system.web>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" />
</staticContent>
<handlers accessPolicy="Script,Read">
<add name="AuthorizedFile" path="*" verb="*"
type="MediaFileAccess.AuthorizedMediaHandler,MediaFileAccess"
preCondition="integratedMode" />
</handlers>
</system.webServer>
</configuration>
The handler which is registered in the web.config:
public class AuthorizedMediaHandler : IHttpHandler, IDependency
{
private readonly IAuthenticationService _authenticationService;
public AuthorizedMediaHandler(IAuthenticationService authenticationService)
{
_authenticationService = authenticationService;
}
public bool IsReusable { get { return false; } }
public void ProcessRequest(HttpContext context)
{
// Do something using the injected services...
}
}
When I navigate to a Media item url system throws MissingMethodException. That's normal because system cannot find the parameterless constructor.
So, how can I inject the Orchard services into a IHttpHandler?