Retrieving the currentNodeId using umbraco.NodeFactory.Node.getCurrentNodeId()
Hello All,
I am attempting to retrieve the current Node Id from .NET in order to get all the available domains but I am getting an error on the first line which retrieve the currentNodeId - Object Reference not set to an instance of an object. Any ideas of a remedy?
Here is the code snippet
int _currentNodeId = umbraco.NodeFactory.Node.getCurrentNodeId(); //Receiving an error here
List<string> _cultureLists = new List<string>(); Domain[] _domains = umbraco.library.GetCurrentDomains(_currentNodeId);
foreach (Domain d in _domains) { _culttureLists.Add(d.Language.CultureAlias); }
Hi. Could you tell in what context you make this api call? Because actually, the ID of the current node becomes available only after a certain stage of http request processing.
Yes this is in a usercontrol which has been compiled and placed in the usercontrols subfolder in umbraco.
Testing it from Visual Studio and running it from umbraco after adding it as a Data type and selecting umbraco user control wrapper option for the Render control gives this error.
Paul, it seems to me that the curent node id would not be accessible this way from within a data type control (like a user control wrapper). But probably the solution could be getting it from the query string (Request.QueryString["id"]) since the document editor actually is an iframe where the query string include the id of a node being currently edited (like editContent.aspx?id=xxx).
That will make defining a datatype difficult if one has to be culture aware, since the datatype must be defined in umbraco at the backend and not at the web site.
I attempted to use the umbracoUrlName property where I define the url for the page as - myPage?id=culture, since we may not specify the .aspx extension using the umbracoUrlName property. After saving, the link changes to myPageid=culture.aspx, so this will not work.
Hi again. Paul, am I right that you just want to get something like a current locale? Then I could suggest that you could just get the domain part of a current request URL, then get the Domain with Domain.GetDomain(domainName) and then get the Domain.Language property of the result. Does that resolve your issue?
How do you determine the domainName string to pass?
If this were a usercontrol that was used to populate a page, I'll gladly set a DictionaryItem with the domainName or cultureAlias. But this is being used to configure a custom DataType's where the Render Control is set to a umbraco user control wapper.
Retrieving the currentNodeId using umbraco.NodeFactory.Node.getCurrentNodeId()
Hello All,
I am attempting to retrieve the current Node Id from .NET in order to get all the available domains but I am getting an error on the first line which retrieve the currentNodeId - Object Reference not set to an instance of an object. Any ideas of a remedy?
Here is the code snippet
int _currentNodeId = umbraco.NodeFactory.Node.getCurrentNodeId(); //Receiving an error here
List<string> _cultureLists = new List<string>();
Domain[] _domains = umbraco.library.GetCurrentDomains(_currentNodeId);
foreach (Domain d in _domains)
{
_culttureLists.Add(d.Language.CultureAlias);
}
Hi. Could you tell in what context you make this api call? Because actually, the ID of the current node becomes available only after a certain stage of http request processing.
The call is made in a method called from the Page_Load Event in .NET
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
...
string = getCurrentCulture();
...
} else if (Page.IsPostBack) {
...
}
}
private string getCurrentCulture()
{
int _currentNodeId = umbraco.NodeFactory.Node.getCurrentNodeId(); //Receiving an error here
List<string> _cultureLists = new List<string>();
Domain[] _domains = umbraco.library.GetCurrentDomains(_currentNodeId);
foreach (Domain d in _domains)
{
_culttureLists.Add(d.Language.CultureAlias);
}
...
}
I still get the error if I place the call in the Page_Init(object sender, EventArgs e) {} Event.
If I place the call in the Page_PreInit(object sender, EventArgs e) {} Event. The usercontrol runs but it does not return any data.
I am attempting to create a custom DataType for use in umbraco.
Ok, and where is this Page_Load method? Is it some regular aspx page (like the ones inside ~/umbraco)?
Yes this is in a usercontrol which has been compiled and placed in the usercontrols subfolder in umbraco.
Testing it from Visual Studio and running it from umbraco after adding it as a Data type and selecting umbraco user control wrapper option for the Render control gives this error.
Depending on the current culture, I will present a list of culture sensitive options within a drop down list box to the end user.
Paul, it seems to me that the curent node id would not be accessible this way from within a data type control (like a user control wrapper). But probably the solution could be getting it from the query string (Request.QueryString["id"]) since the document editor actually is an iframe where the query string include the id of a node being currently edited (like editContent.aspx?id=xxx).
That will make defining a datatype difficult if one has to be culture aware, since the datatype must be defined in umbraco at the backend and not at the web site.
I attempted to use the umbracoUrlName property where I define the url for the page as - myPage?id=culture, since we may not specify the .aspx extension using the umbracoUrlName property. After saving, the link changes to myPageid=culture.aspx, so this will not work.
This looking for other suggestions on this. I used the following snippet which compiles and I'm able to generate a Custom DataType:
List<Language> _cultureLists = Language.GetAllAsList().ToList<Language>();
but the data presented within the DropDownListBox is not culture aware.
How do I find the current language setting of umbraco?
Hi again. Paul, am I right that you just want to get something like a current locale? Then I could suggest that you could just get the domain part of a current request URL, then get the Domain with Domain.GetDomain(domainName) and then get the Domain.Language property of the result. Does that resolve your issue?
How do you determine the domainName string to pass?
If this were a usercontrol that was used to populate a page, I'll gladly set a DictionaryItem with the domainName or cultureAlias. But this is being used to configure a custom DataType's where the Render Control is set to a umbraco user control wapper.
For example you can try this way:
We are very close. The HOST_NAME is not one of the accepted server variables.
Oh. I made a tipo. Sure I meant "HTTP_HOST" instead of "HOST_NAME" :-)
Great. It work! Thanks a lot for your assistance.
is working on a reply...