c# - Call StaticFileHandler -


i have httphandler mapped aspnet_isapi.dll perform custom authentication check on static files (.pdf files) using iis 7.5 in classic mode:

void ihttphandler.processrequest(httpcontext context) { if(!user.ismember) { response.redirect("~/login.aspx?m=1"); } else { //serve static content } } 

the above code works fine, except else statement logic. in else statement, want allow staticfilehandler process request, haven't been able sort out. suggestions on how "hand off" file iis serve request normal staticfile request, appreciated.

to answer question directly, can create staticfilehandler , have process request:

// serve static content: type type = typeof(httpapplication).assembly.gettype("system.web.staticfilehandler", true); ihttphandler handler = (ihttphandler)activator.createinstance(type, true); handler.processrequest(context); 

but better idea might create http module instead of http handler:

public class authenticationmodule : ihttpmodule { public void dispose() { } public void init(httpapplication application) { application.authorizerequest += this.application_authorizerequest; } private void application_authorizerequest(object sender, eventargs e) { httpcontext context = ((httpapplication)sender).context; if (!user.ismember) context.response.redirect("~/login.aspx?m=1"); } } 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

c++ - Accessing inactive union member and undefined behavior? -

php - Get uncommon values from two or more arrays -