httpmodule

Processing static files via HttpModule in ASP.NET

老子叫甜甜 提交于 2020-01-01 03:46:08
问题 I have statiс files in website folder, but need to check permissions for every file. I decided to use HttpModule for that purposes. ASP.NET receives all the http-requests (I used wildcard mapping) and The algorith is the following: HttpModule receives the request HttpModule checks permissions If access is denied then the answer is "Forbidden". If all is OK then httpModule's method just returns. DefaultHttpHandler is automatically used to process request for static files The problem is that

asp.net file downloading - track downloaded size

别等时光非礼了梦想. 提交于 2019-12-30 08:25:50
问题 I am trying to design a system for something like this with ASP.net/C#. The users pay for downloading some content (files- mp3s/PDFs,doc etc).I should be able to track the number of bytes downloaded by the user. If the number of bytes downloaded match the number of bytes on the server, I should set a flag in DB (telling that the download was successful and prevent them from downloading the file again/asking them to pay for the download again). If the download was incomplete, they should be

How do I execute a controller action from an HttpModule in ASP.NET MVC?

我只是一个虾纸丫 提交于 2019-12-30 05:27:15
问题 I've got the following IHttpModule and I'm trying to figure out how to execute an action from a controller for a given absolute or relative URL. public class CustomErrorHandlingModule : IHttpModule { #region Implementation of IHttpModule public void Init(HttpApplication context) { context.Error += (sender, e) => OnError(new HttpContextWrapper(((HttpApplication)sender).Context)); } public void Dispose() {} public void OnError(HttpContextBase context) { // Determine error resource to display,

IHttpHandler vs IHttpModule

断了今生、忘了曾经 提交于 2019-12-28 07:35:50
问题 My question is simple (although the answer will most likely not be): I'm trying to decide how to implement a server side upload handler in C# / ASP.NET. I've used both HttpModules (IHttpModule interface) and HttpHandlers (IHttpHandler interface) and it occurs to me that I could implement this using either mechanism. It also occurs to me that I don't understand the differences between the two. So my question is this: In what cases would I choose to use IHttpHandler instead of IHttpModule (and

Can an HttpModule invoke a new IE pop-up window?

我只是一个虾纸丫 提交于 2019-12-25 09:33:54
问题 I am developing a custom application feedback tool. The idea is that when the user launches a particular application, I want a pop-up to appear, say a couple seconds after the user launches the application, that asks if they'd be willing to provide feedback. The pop-up will simply be a new IE window. So, something similar in functionality to: Response.Write("<script>window.open('" + sUrl + "', 'mywindow','resizable= yes,scrollbars= yes');</script>"); We have numerous web apps (ASP.NET) in our

Redirecting from Global.asax in Medium Trust

倾然丶 夕夏残阳落幕 提交于 2019-12-24 19:23:10
问题 I am attempting to do a redirect in the Application_Error handler in Global.asax. Nothing fancy at all. private void Application_Error(object sender, EventArgs e) { // ...snip... Server.Transfer(somePath, false); // ...snip... } This works great under Full trust, but I need to get it to work under Medium trust. The code I'm working on here needs to function properly in a shared hosting environment (Unfortunately, I have no control over this requirement). However, when I configure the site as

Can't find httpModules and httpHandlers inside machine.config

半世苍凉 提交于 2019-12-24 09:28:51
问题 I've read a post about httpHandlers and httpModules in ASP.NET and it said that there are such nodes (<httpModules> and <httpHandlers>) defined by default inside machine.config but when I looked they are not there. I've searched the machine.config at path "$WINDOWS$\Microsoft.NET\Framework\$VERSION$\CONFIG". The only references are these 2 lines: <section name="httpHandlers" type="System.Web.Configuration.HttpHandlersSection, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken

How should I reference an IHttpModule instance in the pipeline?

我的未来我决定 提交于 2019-12-24 09:28:08
问题 An IHttpModule implementation I created public class ResponseTweaker : IHttpModule { // my module ... is registered in Web.config <system.web> <httpModules> <add name="redman" type="ResponseTweaker"/> </httpModules> and an instance of it is sitting in the pipeline. From the perspective of a caller (e.g. from the Global.asax.cs file), how should I get a reference to that module instance? 回答1: The modules can be found in HttpContext.Current.ApplicationInstance.Modules . You can look through the

How to test HttpApplication events in IHttpModules

拥有回忆 提交于 2019-12-24 03:27:59
问题 I am writing HttpModule and need to test it, I am using C# , .NET4.5.2 , NUnit and Moq . Method I am trying to test is Context_BeginRequest : public class XForwardedForRewriter : IHttpModule { public void Init(HttpApplication context) { context.BeginRequest += Context_BeginRequest; } public void Context_BeginRequest(object sender, EventArgs e) { ... } } sender here is HttpApplication and this is where the problems start,... one can create instance of HttpApplication however there is no way to

What is Webform's “UrlAuthorizationModule.CheckUrlAccessForPrincipal” equivalent for MVC?

最后都变了- 提交于 2019-12-24 01:53:59
问题 I got a problem as i am writing a custom SSO solution for my company. To mkae it simple, i've made a custom authentication httpmodule that intercepts all requests so as to check user authentication state. If not authenticated, user is redirected to my custom sso login page. The thing is, when user is not authenticated, i'd like to check if he can access the requested page/resource... With Webforms, no problem, i add an authorization block in web.config, and i use UrlAuthorizationModule