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

  • Thread starter andy6 via DotNetMonster.com
  • Start date
A

andy6 via DotNetMonster.com

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/selectedindexchanged. 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.Configuration;

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

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

public void GetHeadersAndValues(string userName, string roleName)
{
User = userName;
Role = roleName;
DBName = ConfigurationManager.AppSettings["databaseName"].
ToString();
SrvrName = ConfigurationManager.AppSettings["serverName"].
ToString();
}

// In the Init function, register for HttpApplication
// events by adding your handlers.
public void Init(HttpApplication application)
{
application.BeginRequest += (new EventHandler(this.
Application_BeginRequest));
application.EndRequest += (new EventHandler(this.
Application_EndRequest));
}

private void Application_BeginRequest(Object source, EventArgs e)
{
// Create HttpApplication and HttpContext objects to access
// request and response properties.
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.AppendHeader("HTTP_SM_USER", User);
context.Response.AppendHeader("HTTP_SM_ROLES", Role);
context.Response.AppendHeader("HTTP_CA_DATABASE_NAME", DBName);
context.Response.AppendHeader("HTTP_CA_SERVER_NAME", SrvrName);
}

private void Application_EndRequest(Object source, EventArgs e)
{
HttpApplication application = (HttpApplication)source;
HttpContext context = application.Context;
context.Response.Redirect(ConfigurationManager.AppSettings["url"].
ToString());
}

public void Dispose()
{
}


}
}

========= web.config snippet ===============
<httpModules>
<add name="AddHeadersModule" type="collaboration.
CreateCustomHeaders,collaboration"/>
</httpModules>


==========default.aspx.cs ==============
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;

namespace collaboration
{
public partial class _Default : System.Web.UI.Page
{
CreateCustomHeaders cch = new CreateCustomHeaders();

protected void Page_Init(HttpApplication app)
{

}

protected void Page_Load(object sender, EventArgs e)
{
}

protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs
e)
{
if (ddlUsers.SelectedItem.Value == "Install")
cch.GetHeadersAndValues("Install", "SuperUser");

if (ddlUsers.SelectedItem.Value == "351676A")
cch.GetHeadersAndValues("351676A", "Biller");

}
}
}

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

Select a user for Claims Control:&nbsp;

<asp:DropDownList ID="ddlUsers" runat="server" AutoPostBack="True"
OnSelectedIndexChanged="ddlUsers_SelectedIndexChanged">

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

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

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

</asp:DropDownList>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,709
Latest member
AustinMudi

Latest Threads

Top