I want to protect my media by a genericHandler.ashx. I have a rewrite rule /media to /handlers/my-handler.ashx?media-url=xxx.jpg But I cannot find a function in umbraco api to get nodeId from url.
At the moment I use this sql query :
public static Int32 GetNodeIdFromUrl(String url)
{
SqlParameter[] sqParams = { new SqlParameter("@url", url) };
string sql = "select contentNodeId from cmsPropertyData where dataNvarchar = @url";
int id = -1;
try
{
id = (int)SqlHelper.ExecuteScalar(umbraco.GlobalSettings.DbDSN,CommandType.Text,sql,sqParams);
}
catch (Exception ex)
{
umbraco.BusinessLogic.Log.Add(
umbraco.BusinessLogic.LogTypes.Error,
new umbraco.BusinessLogic.User(0), 0,
"Error from download security handler ->" + ex.Message.ToString());
}
return id;
}
inspired by http://our.umbraco.org/forum/developers/api-questions/4284-getting-media-Id-from-path
do you know any umbraco api function to do this before ?