Custom HTTPModule - How To Tell When Writing Last Block Of HTML In Write Method

Jul 2, 2010

I have written an Http Module that hooks onto the Response.Filter property of the current request and does various replacements within the HTML before it is sent to the client.All the work is done in the Write method which is overriding Write in the base class Stream.

The Write method is called multiple times for a single response - the HTML seems to be written to the output stream in chunks. My problem is that I don't have an efficient & reliable way of telling if the current chunk is the last chunk (for why I want to know this see below). The only way I have come up with is to check if the chunk contains a closing html tag - but this is not very efficient or reliable.

The reason this is needed is that the module must add the "Refresh" HTTP header to the response, but only if the HTML fulfills certain conditions (and there are certain conditions that mean the header must not be added). So, only when the last chunk has been seen does the code know if the header can be added or not. So, I either need a test for the last chunk, or on each call to Write I add the header if the current block of HTML passes the test (if it has not already been added) or remove the header if the current block of HTML fails the test (if it has already been added).

So, is there a better way to test for the last chuck OR is there a way to test for a particular header being in the response and delete it (there doesn't seem to be a way to do this - only to append headers)?

View 1 Replies


Similar Messages:

HttpHandlers / Modules :: Getting Exception Info From Catch Block To Application_Error Event Of HttpModule?

Oct 7, 2010

regarding one issue I am facing. I created a httpmodule for hadling the unhandled errors and I need to log those errors using log 4 net in database.Everting working fine but I am not getting any error information once the error was hadled and I need that info too. I want to make it as a centralize module which can trap all errors and log those errors.How call application_error event of httpmodule from catch block...so that I can log that info there and I no need log in every catch block..

View 1 Replies

C# - HttpModule To Write Out JavaScript Script References To The Response

Mar 11, 2010

On my page in the Page_Load event I add a collection of strings to the Context object. I have an HttpModule that will fire EndRequest and retrieve the collection of strings. What I then do is write out a script reference tag (based on the collection of strings) to the response. The problem is that the page reads the script reference but doesn't retrieve the contents of the file (I imagine because this is occurring in the EndRequest event). I can't fire the BeginRequest event because I won't have access to the Context Items collection.

I tried to also registering an HttpHandler which Processes the request of the script reference but I can't access the collection of strings in the Context.Items from there.

[code]....

View 2 Replies

How To Call Custom Html Helper From A Controller Method

Dec 30, 2010

I'm trying to write a controller method that returns an ActionResult.

In this method, i would like to:

1. call an HTML helper method

2. Capture and store the HTML helper's rendered HTML in a string

3. Return the method with the rendered HTML wrapped as a JSON

How do i call the Html Helper method from my controller method? Simply using the static class HtmlHelper does not work.

View 1 Replies

How To Make A Custom Strongly Typed Html Helper Method

Dec 2, 2010

Now I found out how to create custom html helpers

using System;
namespace MvcApplication.Helpers {
public class InputlHelper {
public static string Input(this HtmlHelper helper, string name, string text) {
return String.Format("<input name='{0}'>{1}</input>", name, text);
}
}
}

Now how to turn it into a strongly typed helper method InputFor Like it is in the framework?I don't need the Html.TextBoxFor method, I know it exists. I am just curious in how to implement this behavior myself and used this as a simple example.PS. I was looking in the mvc source code but couldn't find a trace of this mysterious TextBoxFor. I only found TextBox. Am I looking at the wrong code?

View 1 Replies

Web Forms :: When And Where To Write Try Catch Block

Mar 31, 2010

When to write try catch block?

Should I write it for each method or only in event handlers or ????

What happens when an exception occurrs? What is the stack for exception?

If I use it at entry point (event handlers) then how do I get actually at which line error occurred?

Suppose an exception was thrown from Data Access Layer How do I get it in presentation layer that exactly in which class method at which line why that error occurred?

Is it true that excessive use of try catch makes application slow?

View 3 Replies

HttpHandlers / Modules :: Trying To Write An HttpModule That Will Work In IIS7 With Integrated Pipeline Mode AppPool?

Jan 2, 2011

am trying to write an HttpModule that will work in IIS7 with integrated pipeline mode AppPool. Within this module I need to access Session variables and to be able to capture the Session Start and End events. I have found a couple of articles on this topic that indicate the need to modify the behavior of the HttpHandler in PostAcquireRequestState to force the Session for the context to be initialized. The article I am using as a template is posted here:[URL]In my case I am getting the following error:

[NullReferenceException: Object reference not set to an instance of an object.] System.Web.PipelineModuleStepContainer.GetEventCount(RequestNotification notification, Boolean isPostEvent) +30 System.Web.PipelineStepManager.ResumeSteps(Exception error) +1112
System.Web.HttpApplication.BeginProcessRequestNotification(HttpContext context, AsyncCallback cb) +113 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +616

I believe that this error implies a problem with attempting to attach an event handler multiple times. I am aware that the modules Init function can be called more than once and have set a static initialization flag which ensures that I will only ever attach the event handler once.In the most condensed form my code is as follows:

public class HttpModule : IHttpModule, IRequiresSessionState

View 1 Replies

Web Forms :: Try / Catch Block Won't Write Javascript?

Jun 10, 2010

Since everyone yells at me that MessageBox doesn't work when the project is uploaded to the server, I need to migrate to javascript alert box. As I was changing my MessageBoxes, I tested and found that they weren't being produced. I'm not sure if it matters, but they are in a try/catch block, which is shown here:[Code]....

This all worked before when I had MessageBox - it showed, then the page redirected when I clicked Ok.

I either don't understand how try/catch works, the javascript isn't adding, or Response.Redirect is executed before I can see the alert box and click Ok on it.

(just as a note, everything works fine, but the alert box doesn't show)........if I add the (javascript) code before the try block, the alert box comes up, so it's not something wrong with the writing of the javascript or executing it at least (I think).

View 7 Replies

Web Forms :: Write In Chunks / Parameters Are Not Supported For The Write Method

Mar 29, 2011

I am reading in a file into a string. Then I am writing this string to a stream. I know this code works fine.

The only problem that I have is with the line that write the data in chunks where the parameters is not supported for the Write method.

The line that has the problem is this line. What do I need to change here?

OutPut.Write(buffer, 0, Math.Min(to_write, WRITE_CHUNK));

[Code]....

View 2 Replies

How Many Times Does HttpModule Init() Method Get Called During Application's Life

Jul 30, 2010

Web application initialization is as follows:

As we know when IIS receives the first request for a particular Asp.net application resource, IIS creates an instance of a HttpApplication (defined in global.asax codebehind).When this new instance is created it's initialization happens that also checks all configured HTTP modules.All modules are then instantiated and put in the application's Modules collection (of type HttpModuleCollection)modules are looped through and their Init() method is called (when they register for request events)

As far as I understand it the above scenario happens when a web application is started/initialized (hence application start event).What happens with modules?

Are they (re)instatiated on each request or reused from the Modules property on each consecutive request while the web application is alive? As I understand IIS and Asp.net they are reused through the whole life of a web application.

If they are reused, can we assume that their Init() method is actually a pseudo event handler for application start event? The thing is we can't attach to application level events within http modules. But if they are being reused we could use Init() as application start event and do whatever we'd put in global.asax instead.

Question,Can we assume that module's Init() method is called only on application start event? Could we use this assumption to i.e. register routes for applications whose global.asax codebehind we can't change? web.config is usually accessible and we can change it the way we want.Would this actually work?

Additional info,We can check HttpApplication code and check its InitModulesCommon() method. This one actually calls Init() of each registered HTTP module. What is more interesting is that this method is only used by InitIntegratedModules() and InitModules() methods. Which are both used only in HttpApplication.InitInternal() method. This is the basis of my assumptions, but I would like to know whether someone has abused IHttpModule.Init() for application start event.

View 3 Replies

C# - Selecting HttpHandler From Custom HttpModule?

Feb 17, 2011

I have an HttpModule and I'd like to choose the HttpHandler for the current request, is that possible? Also web.config is not an option because the condition is not based on path or extension. My googling skills have failed me, no matter what keywords I use all the results are "IHttpHandler vs IHttpModule".

View 3 Replies

Using Custom HttpModule With Ajax Enabled (ScriptManager) Webform?

Mar 4, 2011

I've a custom Httpmodule which handles PostAuthenticateRequest & PreRequestHandlerExecute events.

However, when I try to use the module on page with ReportViwer (which needs ScriptManager) I get a bunch of browser errors such as following and the report viewer does not work as expected i.e. it doesn't show any result.

ASP.NET Ajax client-side framewook failed to load.
'Sys' is undefined
Syntax error (WebResource.axd)
'Type' is undefined (ReportViewerWebControl.axd)

If I comment out the module from web.config everything works as expected (obviously without the module code).

View 1 Replies

AJAX :: Data In A Web Method Block?

Sep 3, 2010

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

public static string[] GetCompletionList(string prefixText, int count, string contextKey) {

// Create array of movies [code]..

Problem: The above code works great for me in getting the Autocomplete AJAX control to work. However, what I need is to define the string[] variable outside of the above block. What I'm looking for is the way to define such a variable as a global, or whatever the technical term in asp.net is for a variable that is persistent and recognized wherever it is used in the code-behind. without massive amounts of technical wizardry?

View 3 Replies

Gets Error While Writing Response.write() On Click Event Of Button

Mar 26, 2010

Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near ' i have kept button in updatepanel and i am getting this error

View 2 Replies

Web Forms :: Email Composer / Create A Write New Post Like Editor (in Which Im Writing)?

Mar 7, 2010

Can v create a Write New Post like editor (in which im writing) with ASP.NET controls n without using Java Script that do the following tasks:

Bold, Italic, Underline, Image insertion etc.

View 2 Replies

How To Use An Extension Method From A Code Block In Aspx Page

Mar 23, 2010

I have an extension method which I can use from the .cs codebehind of an aspx page, but if I try to do it in a code block in the aspx, it can't find the extension method. Is there something I need to add to the page?

View 2 Replies

Use Of Writing Method As Webmethod In Cs File?

Dec 1, 2010

1.What is the use of writing method as webmethod in cs file

2.what is the use of calling webmethods through javascript file.

View 4 Replies

ASP.NET: What Does HttpModule Do - System.ServiceModel.Activation.HttpModule

May 31, 2010

the purpose of this HttpModule? It's showing up on my HttpModuleCollection list, but I don't know what's it's for.System.ServiceModel.Activation.HttpModule

View 3 Replies

Web Forms :: Object Synchronization Method Was Called From Unsynchronized Block Of Code

Jul 27, 2012

l Im downloading Pdfs using WebClient I used below code

try {
WebClient wc = new WebClient();
Uri uriadd = new Uri(@"ftp://xxx.yyy..../httpdocs/FH/Foldername/" + clientorder1[i].Cloi_id + ".pdf");
wc.Credentials = new NetworkCredential("xxxx", "zzzz");
}

Its working fineĀ  but some times Gives Error like Object synchronization method was called from an unsynchronized block of code.. Why this Error coming ....

View 1 Replies

.net - Custom HttpHandler To Block Downloads Of .wmv Files?

Jan 4, 2010

I create a custom http handler to block download of .wmv files e.g. www.pakdev.net/videos/file.wmv (blocked by httpHandler).

But the problem is that now silverlight cannot also stream these video files as they are blocked too.

View 1 Replies

Security :: Custom HttpHandler To Block .wmv Files?

Jan 4, 2010

On my website, www.pakdev.net, I create screencasts to which are streamed through silverlight.

I create a custom handler to block the download of .wmv files from the url like [URL]

But the problem is now the silverlight has also stopped streaming files.

View 1 Replies

Web Forms :: Javascript Block Must Be Placed Before Html?

Jun 6, 2010

I'm new to ASP.net 3.5 and creating a test web site. I have created a master page for my web site with page content blocks. Now I want to use some javascript on the client side to provide for more interaction. I would normally create page specific Javascript functions and insert them in a <script block on the page. Howevere the Javascript script block must be placed before the <HTLM block. If I'm using Master Pages, it doesn't seem that I can use page specific Javascript functions. How can I resolve this problem? I think my options are

1) Don't use Javascript. Use ? instead to write client-side code.
2) Don't use Master Pages because you cannot use Page Specific Javascript functions.
3) Here's how to insert Javascript Functions in a Page with a Master Page.

View 2 Replies

How To Convert Block Of Html To An Image (e.g. Jpg)

Jul 2, 2010

I like to convert html for example a table to and image and save as jpg.(what I mean is that a table displayed on web page, I only want to get that specific table and save as image) Is it possible using asp.net?

View 4 Replies

Custom Server Controls :: Why Custom Control Write Data Only One Time

Dec 26, 2010

I have built a custom control. when i add this custom control in my page twice or more then the it write only one time of its render contest data.

View 4 Replies

Web Forms :: Reading And Writing Data Using POST Method

Aug 24, 2010

I have a web page (Provider) that creates an XML file to be send to the Requester in this fashion:

1. A Requester page needs to send an XML file to the provider page
2. Provider will read the XML file to authenticate the request
3. Provider will Create an xml file with some data.
4. Provider will send the xml file back to the Requester.

Can anyone provide sample code for both the Requestor page (step 1) and the Provider page (steps 2 & 3)

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved