I am trying to create a custom http handler to allow only logged in users to access certain media files (umbraco form uploads)
I have registered it ok and have got an Umbraco context setup however the context does not contain the curremt logged in user.
In the following code 'user' is always null
public class FormFileHandler : IHttpHandler, IRequiresSessionState
{
public bool IsReusable
{
get { return false; }
}
public void ProcessRequest(HttpContext context)
{
UmbracoContext.EnsureContext(
new HttpContextWrapper(HttpContext.Current),
ApplicationContext.Current,
true);
var user = UmbracoContext.Current.Security.CurrentUser;
if (user ==null)
{
context.Response.AddHeader("Location", "/umbraco/");
context.Response.StatusCode = 401;
context.Response.End();
}
}
}
Has anyone done anything similar and managed to access the current logged in user from a httphandler?
Logged in user from http handler.
Hi,
I am trying to create a custom http handler to allow only logged in users to access certain media files (umbraco form uploads)
I have registered it ok and have got an Umbraco context setup however the context does not contain the curremt logged in user.
In the following code 'user' is always null
Has anyone done anything similar and managed to access the current logged in user from a httphandler?
Thanks
Carl
After a bit more digging I found a post about how the logged in user is not set unless you are actually in the back end of Umbraco
So... You have to do something like the following :
any interest in this as a package when I've finished? as I have the whole file response to add in so will be too big to post all the code.
Thanks
Carl.
is working on a reply...