// In a user control or page
string sessionId = this.Session.SessionID;
// In a normal class, running in a asp.net app.
string sessionId = System.Web.HttpContext.Current.Session.SessionID;
According to Dino Esposito each session is stored in the application's Cache and with some work you can retreive this information:
DataTable dt = new DataTable();
dt.Columns.Add("SessionID", typeof(string));
foreach(DictionaryEntry elem in Cache) {
string s = elem.Key.ToString();
if (s.StartsWith("System.Web.SessionState.SessionStateItem")) {
DataRow row = dt.NewRow();
char[] parms = {':'};
string[] a = s.Split(parms);
row["SessionID"] = a[1];
dt.Rows.Add(row);
}
}
<httpCookies> entry that is set to requireSSL="true"
but you are not actually using HTTPS: for a specific request, then the
session cookie is not sent (or maybe not returned, I'm not sure which)
which means that you end up with a brand new session for each request.--
Has recibido este mensaje porque estás suscrito al grupo "AltNet-Hispano" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a altnet-hispan...@googlegroups.com.
Para publicar en este grupo, envía un correo electrónico a altnet-...@googlegroups.com.
Visita este grupo en http://groups.google.com/group/altnet-hispano.
Para acceder a más opciones, visita https://groups.google.com/d/optout.
Buenas,
Para webfarming necesitas almacenar la session o en un IIS ha de ser el mismo para los 3 servidores, o en una base de datos SQL. Estas perdiendo sesion, por que almacenas la cookie que contiene el sessionid, pero el server al ir a buscar los datos seriados en la session no los encuentra, ya que estan en la memoria de otro server. No se si me he explicado con claridad, cualquier aclaración me dices.
Saludos.
namespace WebIU.AppCode.siteMapProviders.CMS
{
[SqlClientPermission(SecurityAction.Demand, Unrestricted = true)]
public class SqlSiteMapProvider : StaticSiteMapProvider
{
private Dictionary<int, SiteMapNode> _nodes = new Dictionary<int, SiteMapNode>(16);
private readonly object _lock = new object();
private SiteMapNode _root;
private bool _EsCargaArbol = false;
private string _rolesIniciales = "";
private List<string> _rolesCampanasClientes = new List<string>();
private List<string> _rolesCampanasMediador = new List<string>();
public void Refresh()
{
Clear();
_nodes.Clear();
_root = null;
}
public override void Initialize(string name, NameValueCollection config)
{
// Verify that config isn't null
if (config == null)
throw new ArgumentNullException("config");
if (config.AllKeys.Contains("EsCargaArbolRoles"))
_EsCargaArbol = Convert.ToBoolean(config.Get("EsCargaArbolRoles"));
//clave para cargar el sitemap en base a unos roles
if (config.AllKeys.Contains("RolesIniciales"))
_rolesIniciales = config.Get("RolesIniciales");
// Assign the provider a default name if it doesn't have one
if (String.IsNullOrEmpty(name))
name = "SqlSiteMapProvider";
// Add a default "description" attribute to config if the
// attribute doesn’t exist or is empty
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "SQL site map provider");
}
if (config.AllKeys.Contains("RolesCampanasCliente"))
{
foreach (var rol in config.Get("RolesCampanasCliente").Split(new char[] { ',' }))
{
_rolesCampanasClientes.Add(rol);
}
}
if (config.AllKeys.Contains("RolesCampanas2"))
{
foreach (var rol in config.Get("RolesCampanas2").Split(new char[] { ',' }))
{
_rolesCampanasMediador.Add(rol);
}
}
// Call the base class's Initialize method
base.Initialize(name, config);
// SiteMapProvider processes the securityTrimmingEnabled
// attribute but fails to remove it. Remove it now so we can
// check for unrecognized configuration attributes.
if (config["securityTrimmingEnabled"] != null)
config.Remove("securityTrimmingEnabled");
}
public override SiteMapNode BuildSiteMap()
{
lock (_lock)
{
// Return immediately if this method has been called before
if (_root != null) return _root;
var listado = Seguridad.Dal.NodoSiteMap.DevolverTodosNodosSiteMap();
if (listado.Count == 0) return _root;
// Create the root SiteMapNode and add it to the site map
_root = CreateSiteMapNodeFromDataReader(listado[0]);
AddNode(_root, null);
//eliminamos el nodo introducido
listado.Remove(listado[0]);
// Build a tree of SiteMapNodes underneath the root node
foreach (var reader in listado)
{
var node = CreateSiteMapNodeFromDataReader(reader);
AddNode(node, GetParentNodeFromDataReader(reader));
if (_EsCargaArbol) continue;
//comprobamos si tiene que crearse mas nodos(campañas, noticias, etc...), esto vendrá indicado por el provider que contenga en la BBDD
if (reader.NameProvider == "") continue;
}
return _root;
}
}
protected override SiteMapNode GetRootNodeCore()
{
lock (_lock)
{
BuildSiteMap();
return _root;
}
}
public override SiteMapNode FindSiteMapNode(HttpContext context)
{
var node = base.FindSiteMapNode(context);
return node;
}
public override SiteMapNode FindSiteMapNodeFromKey(string key)
{
var node = base.FindSiteMapNodeFromKey(key);
return node;
}
public override SiteMapNode FindSiteMapNode(string rawUrl)
{
var node = base.FindSiteMapNode(rawUrl);
return node;
}
static int contadorIsAccessibleToUser = 0;
public override bool IsAccessibleToUser(HttpContext context, SiteMapNode node)
{
//If Security Trimming is not enabled return true
if (!SecurityTrimmingEnabled)
return true;
if (node.Title == "Inicio")
return true;
//si no es el raiz y no tenemos permisos para el padre no hay permisos para el nodo
if (node.Title != "Inicio" && node.ParentNode == null)
return false;
//If there are no roles defined for the page
//return true or false depending on your authorization scheme (when true pages with
//no roles are visible to all users, when false no user can access these pages)
if (node.Roles == null || node.Roles.Count == 0)
return true;
//check each role, if the user is in any of the roles return true
//si estamos en la carga del arbol de roles
if (_EsCargaArbol && _rolesIniciales != "")
{
//quitamos los reestrictivos
var rolesNoReestrictivos1 = node.Roles.Cast<string>().Where(role => role.IndexOf("-") != 0).ToList();
if (rolesNoReestrictivos1.Count == 0)
return true;
return rolesNoReestrictivos1.Any(role => _rolesIniciales.Contains(role));
}
//tenemos que controlar los que son negativos y los que son positivos, los negativos son reestrictivos, por los que los positivos los vamos metiendo en un list
var rolesNoReestrictivos = new List<string>();
foreach (string role in node.Roles)
{
if (role.IndexOf("-", System.StringComparison.Ordinal) == 0)
{
if (context.User.IsInRole(role))
return false;
}
else
rolesNoReestrictivos.Add(role);
}
if (rolesNoReestrictivos.Count == 0)
{
//si no hay nodos no reestrictivos y hemos llegado aquí quiere decir que si hay algún nodo es restrictivo pero no aplica a este usuario, por
//lo que ponemos asterisco en todos los roles del menu del sitemap (imprescindible para que la navegación del menu funcione correctamente)
for (var i = 0; i < node.Roles.Count; i++)
{
node.Roles[i] = "*";
}
return true;
}
//ahora comprobamos si el usuario tiene rol de la pagina
var res = rolesNoReestrictivos.Any(role => context.User.IsInRole(role) || String.Equals(role, "*", StringComparison.InvariantCultureIgnoreCase));
return res;
}
private SiteMapNode GetParentNodeFromDataReader(NodoSiteMap reader)
{
// Get the parent ID from the DataReader
var pid = (int)reader.IdNodoPadre;
// Return the parent SiteMapNode
return _nodes[pid];
}
}
}
...