Hi
I have a sitemapprovider that retreives categorydata from a database. The thing is that I need it to retreive data depending on three parameters. One is a querystring parameter and the two other are taken from values stored in cache. But as it is now, I get the same data no matter what. So I guess it get cache somewhere and that ok, untill any of my three parameters get changed then I want it to refresh the data. Or if the querystring parameter is missing it shouldn't show anything.
Maybe a little blury, but I hope you understand and know what I can do about it.
The code is a modified version of Jeff Prosises SqlSiteMapProvider.
public class SqlSiteMapProvider : StaticSiteMapProvider
{
static readonly string _errmsg1 = "Missing store ID";
SiteMapNode _root = null;
string _connect;
public override void Initialize(string name, NameValueCollection attributes)
{
base.Initialize(name, attributes);
if (attributes == null)
throw new ConfigurationErrorsException(_errmsg1);
_connect = Global.ConnectionString();
}
[MethodImpl(MethodImplOptions.Synchronized)]
public override SiteMapNode BuildSiteMap()
{
HttpContext context = HttpContext.Current;
int storeid = Convert.ToInt32(context.Request.QueryString["s"]); //TODO: validation
int lingo1 = Lingo.GetDefault();
int lingo2 = Lingo.GetSecondary();
// Return immediately if this method has been called before
if (_root != null) return _root;
// Create a dictionary for temporary node storage and lookup
Dictionary<int, SiteMapNode> nodes = new Dictionary<int, SiteMapNode>();
// Query the database for site map nodes
using(SqlConnection connection = new SqlConnection(_connect))
{
connection.Open();
SqlCommand command = new SqlCommand("up_CategorySelectByStore", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@storeid", SqlDbType.Int).Value = storeid;
command.Parameters.Add("@lingo2", SqlDbType.Int).Value = lingo2;
command.Parameters.Add("@lingo1", SqlDbType.Int).Value = lingo1;
SqlDataReader reader = command.ExecuteReader();
int id = reader.GetOrdinal("Id");
int parent = reader.GetOrdinal("Parent");
int url = reader.GetOrdinal("Url");
int title = reader.GetOrdinal("Title");
int desc = reader.GetOrdinal("Desc");
if (reader.Read())
{
_root = new SiteMapNode(this, "0", "default.aspx", "Root");
nodes.Add(0, _root);
AddNode(_root, null);
while (reader.Read())
{
SiteMapNode node = new SiteMapNode(this,
reader.GetInt32(id).ToString(), reader.GetString(url),
reader.GetString(title), reader.IsDBNull(desc) ?
"" : reader.GetString(desc));
int parentid = reader.IsDBNull(parent) ? 0 : reader.GetInt32(parent);
SiteMapNode parentnode = nodes[parentid];
nodes.Add(reader.GetInt32(id), node);
AddNode(node, parentnode);
}
}
}
return _root;
}
protected override SiteMapNode GetRootNodeCore()
{
BuildSiteMap();
return _root;
}
}
Om du inte f?rst?r vad det st?r h?r s? kan du inte svenska.