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:
<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