httpmodule

Process html files with HttpModule to catch 404 errors on IIS7

非 Y 不嫁゛ 提交于 2019-12-05 11:59:50
I am having another problem with my HttpModule that handles exceptions. (cfr. my previous post: Custom HttpModule for IIS 7 for integrated ) All works well, but only for aspx pages. The main reason we wanted to use this HttpModule is to handle 404 exceptions that occur when someone tries to go to a html page that doesn't exist. But my HttpModule only works for .aspx pages and it isn't triggered when a html file doesn't exist. This is the configuration that I have set up in my web.conf file: <system.webServer> <modules> <add name="AspExceptionHandler" type="Company.Exceptions

How would an HttpModule for Custom Authentication interact with Windows Authentication?

老子叫甜甜 提交于 2019-12-05 06:27:49
I am trying to create a custom HttpModule which controls which users can view a site. I am trying to leverage Windows Authentication to do this. On an individual page, I would probably do something like this: if (HttpContext.Current.User.Identity.Name.Contains("jsmith")) { Response.Write("You do not have the correct permissions to view this site."); Response.End(); } But because I want to make this more configurable at the application level, I would like to use an HttpModule. Here is the start that I have made on the code: using System; using System.Web; public class CustomAuthHttpModule :

OAuth 2.0 authentication in HTTP Module

久未见 提交于 2019-12-05 04:38:49
Is it possible to implement OAuth(Open Authorization) 2.0 or 1.0 in HTTP Module. Why i m choosing this because, each and every request will first reaches the HTTP Module, so from that request i have to authenticate Is it possible ? If YES means , please like a related link for that Help me.. Yes, this is possible. In fact mod_auth_openidc does exactly that for Apache (and for OpenId Connect, which is a protocol built on OAuth2). More on the scenario here: https://auth0.com/blog/2014/08/22/sso-for-legacy-apps-with-auth0-openid-connect-and-apache/ I'm going to add to Eugenio's answer by saying

Asynchronous HttpModule MVC

做~自己de王妃 提交于 2019-12-04 23:16:24
问题 I have a synchronous HttpModule that contains the following code. /// <summary> /// Occurs as the first event in the HTTP pipeline chain of execution /// when ASP.NET responds to a request. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">An <see cref="T:System.EventArgs">EventArgs</see> that /// contains the event data.</param> private async void ContextBeginRequest(object sender, EventArgs e) { HttpContext context = ((HttpApplication)sender)

How to inject HTML before closing html tag in a HTTPModule

 ̄綄美尐妖づ 提交于 2019-12-04 20:33:46
I'm trying to inject some additional markup in the response but its not outputting as expected. For example the following code will output: ... </html>CONTENT private void OnEndRequest(Object source, EventArgs e) { HttpApplication application = (HttpApplication)source; HttpContext context = application.Context; context.Response.Write("CONTENT"); } But i want the content to output right before the closing html tag ... CONTENT</html> Any ideas on how to achieve this? You should use an HttpContext.Response.Filter . Check this MSDN documentation page: http://msdn.microsoft.com/en-us/library/system

How to limit HttpModule with ONLY ONE call per request?

非 Y 不嫁゛ 提交于 2019-12-04 19:06:47
Here is my implementation of HttpModule: file with module: public class HttpModuleRewriter : IHttpModule { #region IHttpModule public void Init(HttpApplication app) { app.BeginRequest += ProcessRequest; } public void Dispose() { } #endregion #region Protected Methods protected void ProcessRequest(object sender, EventArgs e) { ... } } web.config: <?xml version="1.0"?> <configuration> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="HttpModuleRewriter" preCondition="managedHandler" type="HttpModuleRewriter" /> </modules> </system.webServer> </configuration> I've

Can I be sure that HttpModules are executed in the order in which they are listed in the HttpApplication.Modules collection?

拈花ヽ惹草 提交于 2019-12-04 18:03:50
问题 I want to write an IHttpModule that has to be executed strictly after FormsAuthenticationModule , otherwise it will be useless. There's HttpContext.Current.ApplicationInstance.Modules property that returns a collection of IHttpModule s. I can check that my module is after FormsAuthenticationModule in this collection. Will that be enough? Does that collection list IHttpModule s in the order in which they are executed? 回答1: Recall that modules can subscribe to different pipeline events. Within

Why isn't my custom delivered image caching in the browser?

怎甘沉沦 提交于 2019-12-04 15:37:14
I have a custom handler that is returning an image to the browser. The images are fetched from a database. For some reason the images are not being cached by the browser, and I was wondering if someone might be able to spot what I am missing from the below code: HttpContext.Current.Response.BinaryWrite(imageBytes); HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public); Context.Current.Response.Cache.SetAllowResponseInBrowserHistory(true); if(imgRepGetCache.DateCached.HasValue) HttpContext.Current.Response.Cache.SetLastModified(imgRepGetCache.DateCached.Value); HttpContext

Exception handling using an HttpModule

与世无争的帅哥 提交于 2019-12-04 12:40:59
问题 We're reviewing one of the company's system's exception handling and found a couple of interesting things. Most of the code blocks (if not all of them) are inside a try/catch block, and inside the catch block a new BaseApplicationException is being thrown - which seems to be coming from the Enterprise Libraries. I'm in a bit of a trouble here as I don't see the benefits off doing this. (throwing another exception anytime one occurs) One of the developers who's been using the system for a

Is it safe to use an HttpModule for localization?

最后都变了- 提交于 2019-12-04 10:18:46
I'm considering making use of an HttpModule for localization purposes (based on the example in this article ) - but I'm curious, is this safe? Here's the code, for reference: public class CookieLocalizationModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { context.BeginRequest += new EventHandler(context_BeginRequest); } void context_BeginRequest(object sender, EventArgs e) { // eat the cookie (if any) and set the culture if (HttpContext.Current.Request.Cookies["lang"] != null) { HttpCookie cookie = HttpContext.Current.Request.Cookies["lang"]; string