I am trying to simulate a web-farm environment and I need to implement
a simple ad balancer layer for this(C#/ASP.NET 2.0, IIS 5.1). I am
doing it via folwing architecture. Feel free to suggest any flaws that
can help me resolve the problem.

I have a web-application named LoadBalancer (LB) which has lists of
hosts that it needs to connect. All the hosts are running exactly same
web application. So let’s say when users connects to LB, it takes him/
her to a web-form on app running on Machine1. User hits a button here
but let’s say that Mafchine1 becomes unavailable now, which means that
LB should try connecting to application running on Machine2. This mean
that I need to capture every http request in LB, see which is the
device I am currently connected to , Make sure its avaialble
(otherwise get the availabe machine’s URL) and then post the http
request to that machine. I tried doing it in
Application_PreRequestHandlerExecute event but could not figure out
how to do it. Bew is the simplied code that I currently have in
Gabal.asax.

My questions.
1. Can this be done?
2. My current approach can work?
3. Any code samples will be highly appreicated.

TIA


<%@ Application Language="C#" %>

<script runat="server">

void Application_Start(object sender, EventArgs e)
{
System.Collections.Generic.List<string> ListOfMachines = new
System.Collections.Generic.List<string>();
int index = 0;

// Hard-coded for brevity
ListOfMachines.Add("http://Machine1/MyWebApp/";);
ListOfMachines.Add("http://Machine2/MyWebApp/";);
ListOfMachines.Add("http://Machine3/MyWebApp/";);
Application["MachinesList"] = ListOfMachines;
Application["CurrentIndex"] = index;
}

void Application_End(object sender, EventArgs e)
{
// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
// Code that runs when a new session is started
string NextMachineURL = GetNextAvailableMachine(); // This returns the
URL from MachinesList in round-robin fashion

// *** Establish the request
System.Net.HttpWebRequest HttpReq =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create(NextMachineURL);

// *** Retrieve request info headers
System.Net.HttpWebResponse WebResponse =
(System.Net.HttpWebResponse)HttpReq.GetResponse();

System.IO.StreamReader ResponseStream =
new System.IO.StreamReader(WebResponse.GetResponseStream(), enc);

string strHtml = ResponseStream.ReadToEnd();
System.Web.HttpContext.Current.Response.Write(strHtml);
WebResponse.Close();
ResponseStream.Close();

break;

}

void Session_End(object sender, EventArgs e)
{
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate
mode
// is set to InProc in the Web.config file. If session mode is set to
StateServer
// or SQLServer, the event is not raised.

}



</script>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/DotNetDevelopment

You may subscribe to group Feeds using a RSS Feed Reader to stay upto date 
using following url  

<a href="http://feeds.feedburner.com/DotNetDevelopment";> 
http://feeds.feedburner.com/DotNetDevelopment</a>
-~----------~----~----~----~------~----~------~--~---

Reply via email to