1

I'm just reading about implementing my own HTTP handler for ASP.NET 4.0 and IIS7. This looks really cool. I want special processing for ZIP files and it seems like an HTTP handler is the perfect solution.

However, what's giving me trouble is that the handler must be in a separate assembly. So how can I access the rest of my application from this assembly?

Specifically, I'd like to determine if the user is authenticated and redirect them to the login page if they are not. But User.Identity.IsAuthenticated, etc. will not be available from my handler.

(Yes, I know there are ways to approach this without an HTTP handler but they don't seem appropriate for my specific needs.)

1 Answer 1

1

User.Identity.IsAuthenticated, etc. will not be available from my handler.

The ProcessRequest method gives you the current HTTP context from which you could determine if the user is authenticated:

public void ProcessRequest(HttpContext context)
{
    if (!context.User.Identity.IsAuthenticated)
    {
        // the user is not authenticated
    }
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

You know, I just realized this when going to bed last night. But I don't understand where this is set when it's my own custom HTTP handler. Do you happen to know how it gets set before my handler is called? Otherwise, if this works and I can use IIS7 to map the file to my handler from web.config, then that should be all I need. I won't be able to try this for a couple more hours.
@Jonathan, it doesn't matter that it is your own custom handler. It is an assembly which is part of the same application. The currently logged in user is set by reading the authentication cookie sent from the client.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.