.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to implement custom HttpContext for each request under class that implements IHTTPHandler

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Hello All,

I created an application and implemented IHTTPHandler for all incoming request ending with ".aspx" extension.

Under "ProcessRequest" module, I am creating an instance of HttpContext (with URL attributes different from my application's URL i.e. if I am working on localhost then speciying Yahoo.com as its URL) and assigning it to "context" which comes as method argument.

After redirection, an error is generated. Also, the custom HTTPContext is not passed to the requested page (default.aspx, in my case.)

Code is as follows.

    Public Sub ProcessRequest(ByVal context As System.Web.HttpContext) Implements System.Web.IHttpHandler.ProcessRequest
            Dim requestedUrl As String
            Dim targetUrl As String
            Dim urlLength As Integer
            'Save settings which will be used while redirecting to appropriate page
            requestedUrl = context.Request.RawUrl
            If requestedUrl.IndexOf("?") >= 0 Then
                targetUrl = requestedUrl.Substring(0, requestedUrl.IndexOf("?"))
                targetUrl = requestedUrl
            End If
            If targetUrl = Nothing Or targetUrl.Length = 0 Then
                targetUrl = requestedUrl
            End If

View Complete Post

More Related Resource Links

Cutting Edge: Implement Custom Cache Dependencies in ASP.NET 1.x


One of the most compelling improvements that ASP. NET brought to ASP programming was the Cache object. The Cache has some similarities to the Application object and is a container of global data (as opposed to session-specific data) that features a fair number of innovative characteristics.

Dino Esposito

MSDN Magazine July 2004

HTTP Pipelines: Securely Implement Request Processing, Filtering, and Content Redirection with HTTP


ASP.NET is a flexible and extensible framework for server-side HTTP programming. While most people think of ASP.NET in terms of pages served, there is a lower-level infrastructure sitting beneath this page model. The underlying plumbing is based on a pipeline of app, module, and handler objects. Understanding how this pipeline works is key if you want to get the most out of ASP.NET as an HTTP server platform, while making your process more efficient, and keeping your server secure. This article introduces the architecture of the pipeline and shows how you can use it to add sophisticated functionality to an ASP.NET-based app.

Tim Ewald and Keith Brown

MSDN Magazine September 2002

Microsoft .NET: Implement a Custom Common Language Runtime Host for Your Managed App


While most application developers may not need to write a custom host, understanding what is involved provides a great deal of insight into the architecture of the CLR. After covering how the CLR is started and loaded into a process, how to set the available configuration options, and how a host defines application domains, this article explains how to design a custom host. Important concepts include making the right decisions about the application domain boundaries for the host, configuring them correctly, loading and executing user code, and resolving references to assemblies. Setting security policy and unloading application domains as the application shuts down are also explained.

Steven Pratschner

MSDN Magazine March 2001

Building a Custom Data Grid: Performing Ad Hoc Web Reporting with a VBScript 5.0 Class Object


A flexible, customizable grid for displaying data is a useful tool for ASP developers. It allows Web visitors to customize their view of your data. This article takes the data grid presented in "Ad Hoc Web Reporting with ADO 2.0" by John Papa and Charles Caison (MIND, December 1998) and adds handy features such as a finds feature that supports multiple finds and a mode for adding and editing records. This version also improves response time by allowing asynchronous record download and it componentizes the code so it can be used as a standalone VBScript class object that can be reused in other pages.

Randall Kindig

MSDN Magazine July 2000

Creating a Validator class for a custom activity

I created a new Workflow Activity Library and then added a new Activity called BindForm2Activity. After that I added a new class called BindForm2Validator and then placed an attribute to the BindForm2Activity to link it to the validator class.   Here is the code for each of the classes:   BindForm2Activity.xoml.cs: Code Snippet   using System;using System.ComponentModel;using System.ComponentModel.Design;using System.Collections;using System.Drawing;using System.Linq;using System.Workflow.ComponentModel.Compiler;using System.Workflow.ComponentModel.Serialization;using System.Workflow.ComponentModel;using System.Workflow.ComponentModel.Design;using System.Workflow.Runtime;using System.Workflow.Activities;using System.Workflow.Activities.Rules; using FormsCollection;using Utils; namespace ActivityLibrary{    [ActivityValidator(typeof(BindForm2Validator))] public partial class BindForm2Activity : SequenceActivity {        public static DependencyProperty FormToBindProperty = System.Workflow.ComponentModel.DependencyProperty.Register("FormToBind", typeof(FormsCollection.Form2), typeof(BindForm2Activity));         [Description("Form to bind a datasource to it ")]        [Category("BindForm2ToDataSource")]        [Browsable(true)]        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]        public FormsCollection.Form2 Form

Custom List: Request updates quarterly

I have a custom list of clients. Each client has an owner (person or group column).   I need to be able to request an update each quarter from the person listed in the owner column. What is the best way to achieve this?

Custom markup extension or custom binding class?

Hey experts! I'm doing a project where I've encountered an issue I'd love some feedback on. I've created a custom Markup Extension called MyMarkupExtension, with two properties.  I can use it like below: <cc:DialogBorder Title="{local:MyMarkupExtension MyProperty='property value goes here', AnotherProperty='and another value here'}"> It works, and in 99% of the cases, it fits my needs perfectly.  In 1% of the cases, the values of MyProperty and AnotherProperty can not be set at design time, so I'd need some binding there. <cc:DialogBorder Title="{local:MyMarkupExtension MyProperty={Binding Path='SomePropertyOfTheViewModel'}, AnotherProperty='and another value here'}"> This presents my two questions (yes I did make only one post for 2 questions, bad karma...): 1. the binding inside my markup is not legal, after all, a binding can only be set on a DependencyProperty.  Is there any workaround which I could use for this problem at hand? In case there isnt... 2. I'm thinking about dropping the markup extension and creating a custom binding instead.  For this, I'd have to inherit from bindingbase, and so far I've read online that's one ____ of a nightmare.  Does anyone have some good code / examples on where to start? "The improbable we do, the impossible just takes

Session or Request in class without passing as param

I'd like to be able to reference the asp.net objects Session, Request, from a procedure without passing them in as parameters all the time. Is there a way to do this. For example, now I have namespace xx { public class ContextPT { public static string GetSession(System.Web.SessionState.HttpSessionState inSession) { StringBuilder sb = new StringBuilder(1000); string nameType; string value; foreach (string s in inSession.Keys) { nameType = s + " " + inSession[s].GetType().ToString(); value = inSession[s].ToString(); sb.AppendLine(nameType + ": " + value); // dataRow(new string[] {nameType, value}); } return sb.ToString(); } } } somewhere else this.lContext.Text = ContextPT.GetSession(Session); I'd like to call it like this "ContextPT.GetSession()" and have GetSession know how to find the Session object.  I know this does not seem like a big deal in this case, but I have reasons. 

Sending Array of Custom Class over WCF Problem

I have been attempting to convert some service calls that returned a DataSet into something more lightweight. For instance, I am converting: [OperationContract] public DataSet GetCommittees(); into: [OperationContract] public List<VolunteerCommittee> GetCommittees(); where committee is defined as: [DataContract] public class VolunteerCommittee { [DataMember] public int Id { get; set; } [DataMember] public String Name { get; set; } } I copied the structure of the data contract and the operation contract right from an example in a book I bought on WCF. The author mentioned that the List<VolunteerCommittee> would get converted into an array over the wire, so the client's operation contract looks like: [OperationContract] public VolunteerCommittee[] GetCommittees(); My problem: When the service is called, an empty array is returned every time. When I put trace statements in, I see an array of 48 VolunteerCommittees leaving the server. I've done some reading on the problem and tried a number of suggestions, such as using the XmlSerializer attribute, including a certain namespace as a [return:] on the server's contract, changing the type of binding (it's using wsHttpBinding... I tried basicHttpBinding) and turning off MTOM in the behavior, but none of these changed the empty result of the call. At this point, I'm hoping someone can shine some light on

Query Correlation faliure using custom Request/Reply Message Contract classes.

Hi,I have a service which is correlated by a Guid query. When I'm using designer created Message Content/Parameters feature for message definition, everithing working lika a charm. But If I define custom [MessageContract] Request/Reply classes (where request class has Guid SvcUID property for correlation), and choose'em as Message Content in the designer with proper CorrelatesOn definition of course, I have got a service exception about correlation query faliure. Have you folks tried to apply your custom [MessageContract] classes for correlated communication?

Custom Web Part deployment with class library reference

Hi All, We have class library as a project in our solution as well as a web part project. Our web part simply references and executes a service utility class in the class library and outputs it into a label. The deployment is successful but when attempting to add the web part to the page, it comes out with a error page saying "File Not Found" with a correlation ID and date/time reference. Once we take out the code that executes the utility class, it deploys fine and we're able to add it to the page without any issues. It seems evident that any reference to our class library causes this "File Not Found" issue... but we're not sure how to implement this solution. Any ideas? Do we add the class library dll directly into the GAC?  If so, how? Is there another reference we have to implement in the AssemblyInfo.cs?  If so, what does that look like? Any help is appreciated. Thanks, Eric

How to implement Design-Time drag & drop from Custom Visual Studio Tool Window to WPF Designer

Hi, Could someone tell me if it is possible to intercept a design time drop event coming from a custom Visual Studio tool window onto the cider design surface? I am hoping to use the same API's as those used by the Visual Studio 2010 'Data Sources' tool window, which provides drag & drop data-binding between classes and WPF/Silverlight controls. My requirement is to pass a DataObject (used with the WPF DragDrop API) from my custom Visual Studio WPF tool window treeview to my custom WPF control at design time, read the data and do some binding/XAML manipulation of my own. The drag aspect is simple enough but I can't work out how to accept a drop event from anything other than the toolbox. At the moment, when I drag my treenode over the design surface it shows the 'cannot drop here' cursor. If someone could give me some insight into how the 'Data Sources' tool window allows dragging of treenodes to controls I would really appreciate it. It is obviously possible but which API's are used and are they public? Thanks in advance, Paul  

How would you handle this? Multiple instance of a custom class...


Forgive me if this isn't the appropriate place.

I have the following data.

10484	1	30	0.5011	0.4630	0.5254	0.0081	10.8362
10484	1	30	0.5061	0.4666	0.5363	0.0075	12.2901
10484	1	30	0.5051	0.4688	0.5383	0.0060	12.5718
10484	1	30	0.5064	0.4623	0.5352	0.0074	12.9344
10484	2	30	0.5035	0.4637	0.5371	0.0074	13.1082
10484	2	30	0.5092	0.4726	0.5397	0.0075	11.7046
10484	2	30	0.5051	0.4645	0.5368	0.0060	13.1261
10484	2	30	0.5062	0.4642	0.5392	0.0081	13.2161

 I am using the following class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CvasAdmin.Classes
  public class invitro
    public class invitroDetail
      // pk of the foxpro Dbf
      public double sampleid;

HttpContext.Session A potentially dangerous Request.QueryString value was detected from the client


I have an ashx handler that was working fine in VS2008 but when I upgraded to VS2010 (haven't gone back to VS2008 to double check though) and when I try to grab the value from HttpContext.Request.Params["update"] I get the following error:

+ ex {"A potentially dangerous Request.QueryString value was detected from the client (update=\"<SETIProducts><Produ...\")."} System.Exception {System.Web.HttpRequestValidationException}

"A potentially dangerous Request.QueryString value was detected from the client (update=\"<SETIProducts><Produ...\")."} System.Exception {System.Web.HttpRequestValidationException}

I've read that I can set the validateRequest to false, but I was wondering about the impacts and looking for any other suggestions. 

I know very little about security when it comes to web programming but I thought I should mention that my handler will be running on a internal file server but transmitting data to/from an eCommerce platfo

Problem with adding custom propety to a data class using Linq.



I tried to add a custom property to the data model:

public partial class Department
        public string ExtensionIdName
                return Extension.ExtensionName;

It seems that it works, but when I bind the data to a ListView it shows all the properties except the property I added manualy (ExtensionIdName).

Am I missing something or is there something wrong?

How to implement add/remove functionality in Custom Control


Hi, I am new to CustomControl and need some help to understand it. I am trying to create a custom control derived from Control class. This control will have two collelction (FromItems and ToItems). Now I have to move item from one collection to other after selecting it(kind of picklist control). I have created dependency properties for both item sources and selctedItems in the collections. I am thinking to bind these sources and selcted items in Style. Can you anyone suggest, how to implement the add and remove behavior from the itemSources? I feel this behaviou should be part of control as this is a fix behaviour. I tried to create some routed event but not sure how to raise it. I am planning to style this as Two list boxes and two buttons(to add and remove from destination list). Is it a correct approach? How to proceed?


Regarding Creating Custom Field type Class Inheriting from IFieldEditor Interface and UserControl C


How to enable the hidden labels On Create Column Page after selecting our Custom Field type before just ckicking OK so that all those labels appear.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend