httpmodule

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

…衆ロ難τιáo~ 提交于 2019-12-06 06:48:28
问题 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

Is it safe to use an HttpModule for localization?

廉价感情. 提交于 2019-12-06 06:23:48
问题 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

HttpModule Init method were not called

这一生的挚爱 提交于 2019-12-06 03:44:15
Recently I was implementing a HttpMoudle. and stuck with the error which is said System.NullReferenceException: Object reference not set to an instance of an object. Here is my code . public class MyHttpModuler : IHttpModule { private static IAuthProvider authProvider=null; #region IHttpModule members /// <summary> /// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule"/>. /// </summary> public void Dispose() { authProvider.Dispose(); authProvider = null; } public void Init(HttpApplication application) { authProvider = new

How can I perform XSLT transformations in an HttpModule?

不问归期 提交于 2019-12-06 01:43:45
I've been trying to implement server-side XSLT transformations as an IIS HttpModule. My basic approach is to install a new filter at BeginRequest that diverts writes into a MemoryStream, and then at PreSendRequestContent to transform the document using XSLT and write it to the original output stream. However, even without performing the transformation I'm clearly doing something wrong as the HttpModule appears to work for the first page load and then I get no response from the server at all until I restart the application pool. With the transformation in place I get an empty page the first

How do I attach Visual Studio 2010 to IIS 7 to debug a custom HttpModule written for an existing 3rd party web application

大憨熊 提交于 2019-12-06 01:05:09
First a little background on what I am trying to achieve. I have a client application that is utilizing REST services served by ArcGIS Server and IIS 7. I want to be able to modify the response (remove or add parameters) before the response is sent to the client. Therefore, I am developing a custom HttpModule using Visual Studio 2010 and .NET 3.5 to intercept and modify the response. However, I am having difficulty debugging my custom HttpModule. I can attach to the IIS process using Visual Studio 2010 when it is run as Administrator, however, executing the web 3rd party web application does

Server.TransferRequest() and the http status code

霸气de小男生 提交于 2019-12-06 00:21:17
问题 I had to implement a custom HttpModule to handle a 404 error in Sharepoint. It listens for the PreSendRequestContent event, and looks for a 404 status code. If one is found it does a TransferRequest. void App_PreSendRequestContent(object sender, EventArgs e) { HttpResponse res = App.Response; HttpRequest req = App.Request; if (res.StatusCode == 404 && !req.Url.AbsolutePath.Equals(PageNotFoundUrl, StringComparison.InvariantCultureIgnoreCase)) { App.Server.TransferRequest(PageNotFoundUrl); } }

Asp.net MVC error with configured managed modules

蓝咒 提交于 2019-12-05 22:48:44
I have a custom authentication HttpModule that is pretty strait forward. But I want it to run only for managed requests (and not for static ones). Asp.net MVC automatically adds configuration section for IIS7 web server: <system.webServer> <validation validateIntegratedModeConfiguration="false" /> <modules runAllManagedModulesForAllRequests="true"> <remove name="ScriptModule" /> <remove name="UrlRoutingModule" /> <add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule,..." /> <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule,..." /> <

How to handle application start event in ASP.NET module

心已入冬 提交于 2019-12-05 20:29:54
I am writing an asp.net HTTP module which needs to read configuration data once from a local file (say config.xml stored in application root directory) and then based on configuration perform some processing on incoming requests. Since there is no Application_Start/Application_init hooking available in Asp.NET modules, what would be the best way to handle the scenario. I am trying to avoid reading configuration file each time a request comes. Ideally, I want to read the config file when application starts. I need to code this in http module only and do not want to use Global.asax I'd go for a

HttpResponse filter returns nothing

主宰稳场 提交于 2019-12-05 14:11:58
I have written a HttpModule that I am using to intercept calls the the WebResource.axd handler so I can perform some post processing on the javascript. The module wraps the Response.Filter stream to perform its processing and writes it's changes to the underlying stream. The problem I have is that the script does not get returned to the browser. So as a really simple example that just acts as a pass through, the module looks like this: public class ResourceModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication context) { context.PostRequestHandlerExecute += new

Redirect all naked domain urls to subdomain(www) urls preserving the url, except for one page on IIS/ASP.NET

允我心安 提交于 2019-12-05 12:00:17
Whats the best way to achieve the above? I do know that it can be achieved at HttpModule level. Is it possible just via web.config(easier and faster to code execute). It's easy to do this with the URL rewrite module through the web.config : <rewrite> <rules> <clear /> <rule name="Redirect naked domains to www.domain.com" stopProcessing="true"> <match url="(.*)" /> <conditions logicalGrouping="MatchAll"> <add input="{HTTP_HOST}" negate="true" pattern="^www\." /> <add input="{REQUEST_URI}" negate="true" pattern="^noredirect/forthis/page\.aspx$" /> <add input="{REQUEST_URI}" negate="true" pattern