If I'm developing an application that must accommodate
multiple security levels though secure login and my ASP.NET
web application is spanned across three web-servers (using
round-robin load balancing) what would be the best approach
to maintain login-in state for the users?

Answer Posted / a

using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;
using System.Text;

public partial class UI_Default3 : System.Web.UI.Page
{
public string projTable = string.Empty;
public string projCode = string.Empty;
public string expand = string.Empty;
public string expandAll = string.Empty;
public DataSet dst = null;
protected void Page_Load(object sender, EventArgs e)
{
dst = new DataSet();
dst = PopulateData.LoadProject();
StringBuilder sb = new StringBuilder();

if (Request.QueryString["projCode"] != null) {
projCode = Request.QueryString
["projCode"].ToString();
}

if (Request.QueryString["expand"] != null) {
expand = Request.QueryString["expand"].ToString
();
}

if (Request.QueryString["expandAll"] != null) {
expandAll = Request.QueryString
["expandAll"].ToString();
}

if (expandAll.Equals("1")) {
Session.Remove("projCode");
for (int i = 0; i < dst.Tables[0].Rows.Count;
i++) {
if (Session["projCode"] != null && Session
["projCode"].ToString() != string.Empty) {
Session["projCode"] = Session
["projCode"].ToString() + dst.Tables[0].Rows[i]
["ProjCode"].ToString() + ",";
} else {
Session["projCode"] = dst.Tables[0].Rows
[i]["ProjCode"].ToString() + ",";
}
}
} else if (expandAll.Equals("0")) {
Session.Remove("projCode");
}

if (Session["projCode"] != null && Session
["projCode"].ToString() != string.Empty) {
if (expand.Equals("1")) {
Session["projCode"] = Session
["projCode"].ToString() + projCode + ",";
} else if(expand.Equals("0")) {
Session["projCode"] = Session
["projCode"].ToString().Replace((projCode + ","), "");
}
} else {
if (!projCode.Equals(string.Empty)) {
Session["projCode"] = projCode + ",";
} else {
Session["projCode"] = string.Empty;
}
}

string sProjCode = string.Empty;
sProjCode = Session["projCode"].ToString();

sb.Append("<tr>");
sb.Append("<td>");

if (expandAll.Equals("1")) {
sb.Append("<a href=\"../UI/Default3.aspx?
expandAll=0\">Collapse all</a>");
} else {
sb.Append("<a href=\"../UI/Default3.aspx?
expandAll=1\">Expand all</a>");
}

sb.Append("</td>");
sb.Append("</tr>");

if(dst.Tables[0].Rows.Count > 0){
for (int i = 0; i < dst.Tables[0].Rows.Count;
i++) {
sb.Append("<tr>");
sb.Append("<td>");
if (sProjCode.IndexOf(dst.Tables[0].Rows[i]
["ProjCode"].ToString()) >= 0) {
sb.Append("<a
href=\"../UI/Default3.aspx?projCode=" + dst.Tables[0].Rows
[i]["ProjCode"] + "&expand=0\"><img
src=\"../Images/close.GIF\" /></a>");
} else {
sb.Append("<a
href=\"../UI/Default3.aspx?projCode=" + dst.Tables[0].Rows
[i]["ProjCode"] + "&expand=1\"><img
src=\"../Images/open.GIF\" /></a>");
}
sb.Append("</td>");
sb.Append("<td>");
if (sProjCode.IndexOf(dst.Tables[0].Rows[i]
["ProjCode"].ToString()) >= 0) {
sb.Append("<a
href=\"../UI/Default3.aspx?projCode=" + dst.Tables[0].Rows
[i]["ProjCode"] + "&expand=0\">" + dst.Tables[0].Rows[i]
["ProjDesc"] + "</a>");
} else {
sb.Append("<a
href=\"../UI/Default3.aspx?projCode=" + dst.Tables[0].Rows
[i]["ProjCode"] + "&expand=1\">" + dst.Tables[0].Rows[i]
["ProjDesc"] + "</a>");
}
sb.Append("</td>");
sb.Append("</tr>");

sb.Append("<tr>");
sb.Append("<td colspan=\"2\">");

if ((!sProjCode.Equals(string.Empty) &&
(sProjCode.IndexOf(dst.Tables[0].Rows[i]
["ProjCode"].ToString()) >= 0))) {
DataSet dstNew = new DataSet();
dstNew = PopulateData.LoadDivision
(dst.Tables[0].Rows[i]["ProjCode"].ToString());

sb.Append("<table border=\"1\" >");
sb.Append("<tr>");
sb.Append("<td>Division ID</td>");
sb.Append("<td>Division Name</td>");
sb.Append("</tr>");

for (int j = 0; j < dstNew.Tables
[0].Rows.Count; j++) {
if (j % 2 == 0) {
sb.Append("<tr class=\"row\">");
}else{
sb.Append("<tr
class=\"altRow\">");
}
sb.Append("<td>" + dstNew.Tables
[0].Rows[j]["DivisionID"] + "</td>");
sb.Append("<td>" + dstNew.Tables
[0].Rows[j]["DivisionName"] + "</td>");
sb.Append("</tr>");
}
sb.Append("</table>");
}
sb.Append("</td>");
sb.Append("</tr>");

}
projTable = sb.ToString();
}




}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the uses of reflection?

572


In a page I have gridview with options of select and delete using hyperlink when I am selecting any one of then it has to open another page how can it?

499


What is a SESSION and APPLICATION object?

570


How to create a db connection at one place/page so that we can use that connection for all pages/forms/windows.what r the steps ned to be performed if question not clear,let me know

699


Tell me what is the request flow used for asp.net mvc framework? : asp.net mvc

541






Can you edit data in the Repeater control? Which template must you provide, in order to display data in a Repeater control? How can you provide an alternating color scheme in a Repeater control? What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?

544


What is web router?

495


How does the iis work?

538


when a request is made in Life cycle of ASP.NET page .

525


Differentiate between a page theme and a global theme?

519


Explain how cookies work.

589


can any one find and tell the difference between dot net and php which one is best ? which one we get more salary? which one is stable and which one is best for freshers and also better in future and carrer ? which one we wil get more salary sir ? please send ur valuable suggestions to kiranpulsar2007@gmail.com

1474


How to include silver light .xap page into asp.net web application and what is the purpose of using silverlight application?

2236


For which does this Codebehind="MyCode.aspx.cs" is relevent to ?

573


Why cyclomatic complexity is important?

549