473,624 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Usage of HTTPModule may be improper...what to use?

I want to display a webpage. The user selects a value from a drop down. This
value is put into a custom header and added to the http pipeline. Then the
page is redirected in the EndRequest method to where I need to go.

What works: the dll, the web.config of the module, the addition of the header
and value to the pipeline, redirection to other website and receiving value
(null) on the other website

What doesn't work: Allowing the user to see the default.aspx webpage and
select a value from the drop down.

My internal logic after reading docs was that the dll would not be called
until the dropdown performed AutoPostBack/selectedindexch anged. Then it would
contact the dll and do stuff.

I understand what it's doing. It's inserting itself into the pipeline before
the default.aspx page is even seen.

Am I using the wrong technology for what I want to accomplish? Source code
below.

========= DLL ============
using System;
using System.Web;
using System.Configur ation;

namespace collaboration
{
public class CreateCustomHea ders : IHttpModule
{
string User = "";
string Role = "";
string DBName = "";
string SrvrName = "";

public CreateCustomHea ders()
{
//
// TODO: Add constructor logic here
//
}

public void GetHeadersAndVa lues(string userName, string roleName)
{
User = userName;
Role = roleName;
DBName = ConfigurationMa nager.AppSettin gs["databaseNa me"].
ToString();
SrvrName = ConfigurationMa nager.AppSettin gs["serverName "].
ToString();
}

// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplic ation application)
{
application.Beg inRequest += (new EventHandler(th is.
Application_Beg inRequest));
application.End Request += (new EventHandler(th is.
Application_End Request));
}

private void Application_Beg inRequest(Objec t source, EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
HttpApplication application = (HttpApplicatio n)source;
HttpContext context = application.Con text;
context.Respons e.AppendHeader( "HTTP_SM_US ER", User);
context.Respons e.AppendHeader( "HTTP_SM_ROLES" , Role);
context.Respons e.AppendHeader( "HTTP_CA_DATABA SE_NAME", DBName);
context.Respons e.AppendHeader( "HTTP_CA_SERVER _NAME", SrvrName);
}

private void Application_End Request(Object source, EventArgs e)
{
HttpApplication application = (HttpApplicatio n)source;
HttpContext context = application.Con text;
context.Respons e.Redirect(Conf igurationManage r.AppSettings["url"].
ToString());
}

public void Dispose()
{
}
}
}

========= web.config snippet ===============
<httpModules>
<add name="AddHeader sModule" type="collabora tion.
CreateCustomHea ders,collaborat ion"/>
</httpModules>
==========defau lt.aspx.cs ==============
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.Collecti ons;

namespace collaboration
{
public partial class _Default : System.Web.UI.P age
{
CreateCustomHea ders cch = new CreateCustomHea ders();

protected void Page_Init(HttpA pplication app)
{

}

protected void Page_Load(objec t sender, EventArgs e)
{
}

protected void ddlUsers_Select edIndexChanged( object sender, EventArgs
e)
{
if (ddlUsers.Selec tedItem.Value == "Install")
cch.GetHeadersA ndValues("Insta ll", "SuperUser" );

if (ddlUsers.Selec tedItem.Value == "351676A")
cch.GetHeadersA ndValues("35167 6A", "Biller");

}
}
}

========= default.aspx snippet =============== =

Select a user for Claims Control:&nbsp;

<asp:DropDownLi st ID="ddlUsers" runat="server" AutoPostBack="T rue"
OnSelectedIndex Changed="ddlUse rs_SelectedInde xChanged">

<asp:ListItem Value="" Text="--select--" />

<asp:ListItem Value="Install" Text="Install" />

<asp:ListItem Value="351676A" Text="351676A" />

</asp:DropDownLis t>

--
Message posted via DotNetMonster.c om
http://www.dotnetmonster.com/Uwe/For...p-net/200607/1
Jul 7 '06 #1
0 1190

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1553
by: Bruce B | last post by:
Hi group, I'm experiencing some extreme weirdness over the last week with IIS related to it's Mappings and how .NET is behaving. I can't explain the behavior as it seems very random. Our app has about 50 file extensions that we map in IIS and handle in our HTTPHandler to catch the reference and then lookup the correct content from a database. In addition, we do some magic in a HTTPModule to rewrite paths for file types we don't...
2
3430
by: Rob Mayo | last post by:
What I'm trying to do is Create an ASP.Net app that has both Windows-authenticated users and Anonymous users. The idea is this: When authenticated users attempt to access the site, their credentials are passed to the Request, and I use the DOMAIN\USER value via the AUTH_USER server variable to access their accounts. These people would never have to log in to the app, only their machines on the network. When anonymous users attempt to...
7
2573
by: nail | last post by:
Folks, I develop a HttpModule and it works correct, but one problem is occurs. After I register the httpmodule in the web.config, my pages (not testing http://localhost/site but http://my_machine_name/site) show problems when refresh the page. I guess some kind of javascript problems with the postback methods. Someone has any idea how can i fix it? Thanks
4
6193
by: | last post by:
I have earlier used an HttpModule that did URL rewrites on the BeginRequest event. Now I am trying to use the same module in a different application on a new and upgraded machine (winxp sp2). The Module is registered via Web.config. The registration is OK. When asking for an existing .aspx page, the eventhandler is called as it should. HOWEVER - if the request url is for a non-existant file, I get a 404 - file
4
3907
by: Danny W | last post by:
Hi There! Is it possible to use HttpModule to replace the built-in ASP.NET Session object? I want to write a HttpModule that will handle storing and retrieving of session values from an external database. For example, when a page set values to Session object such as Session("somevar")=1 then I want my HttpModule to get notified and store the value into the external database. The same for "getting" the variable, I want my own...
2
1247
by: craigkenisston | last post by:
I have an asp.net application. This have a very special class that I use all over the site code. I also have an HttpModule which has been working quite fine. Now, due a strange requirement I need to read some properties from my very special class from within the HttpModule. I tried to add the main asp.net dll to the HttpModule and I got an error about I could not do that because it caused a circular reference. So, what's the proper...
2
2130
by: Simon-Pierre Jarry | last post by:
Hi, I created a custom HttpModule for managing the security of my application. in "Init" sub, I regsiter the events doing that : Public Sub Init(ByVal context As System.Web.HttpApplication) Implements IHttpModule.Init httpApp = context
2
4577
by: walter | last post by:
Hi there, I know there is pool of HttpApplications, and for each request coming in, HttpRuntime will dedicate one from pool to serve the request. My questions are : 1. since HttpModule is plug into the process, does each instance of HttpApplication keep its own set of HttpModule instance or HttpModules are shared among all HttpApplication instances? 2. In case of HttpApplication keep its own set of HttpModule, does the HttpModule...
1
1800
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post by:
Hello, I am designing a HTTPModule that tracks and logs all pages visited by user. I am succeeded in that. Now to provide much better experience for the person who monitor's these logs, I need to track the button's clicked on the pages by user also. Is there any way to do this using HTTPModule ? Is it possible to handle which event is going to fire , from an HTTPModule ? I mean if button1 is clicked, is it possible to find out button1...
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2613
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1493
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.