Deleting node in codebehind of a page - The user has no umbraco contextid - try logging in
Hi Guys,
I have moved a scheduled task into a simple aspx page that I'll post to via curl.. so that i could get an http context for deleting nodes as discussed here
Now however I am receiving an error stating: The user has no umbraco contextid - try logging in
So am i correct in assuming I'll need to log an admin user in before running this chunk of code? and if so how would i go about doing that programatically say for example my user in the backend is called "TaskUser" and the password is "password"
Hi Richard.. using reflector it just looks like validateCredentials hits the db to check if the username and password are valid.. good check though.. ill poke around in reflector with the webservices and give it a look:
Deleting node in codebehind of a page - The user has no umbraco contextid - try logging in
Hi Guys,
I have moved a scheduled task into a simple aspx page that I'll post to via curl.. so that i could get an http context for deleting nodes as discussed here
Now however I am receiving an error stating: The user has no umbraco contextid - try logging in
So am i correct in assuming I'll need to log an admin user in before running this chunk of code? and if so how would i go about doing that programatically say for example my user in the backend is called "TaskUser" and the password is "password"
Cheers, Tom
I tried this:
void DeleteItemsForCategory() { try { Document parentNode = new Document(CurrentCategoryId);//use id of parent node foreach (Document child in parentNode.Children) { child.delete(); umbraco.library.UpdateDocumentCache(child.Id); } umbraco.library.RefreshContent(); } catch (Exception ex) { ExceptionReporter.ReportException(ex, "Exception Occurred Trying To Delete Items From Category"); throw ex; } }void CheckUserLogin() { if (HttpContext.Current.Response.Cookies["UserContext"] == null || string.IsNullOrWhiteSpace(HttpContext.Current.Response.Cookies["UserContext"].Value)) { if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].ValidateUser("ServiceUser", "h3lt3rSkelTa*")) { umbraco.BusinessLogic.User u = new User("ServiceUser"); Guid userContextId = Guid.NewGuid(); SqlHelper.ExecuteNonQuery("insert into umbracoUserLogins (contextID, userID, timeout) values (@contextId,'" + u.Id + "','" + (DateTime.Now.Ticks + (_ticksPrMinute * _umbracoTimeOutInMinutes)).ToString() + "') ", SqlHelper.CreateParameter("@contextId", userContextId)); HttpCookie cookie = new HttpCookie("UserContext"); cookie.Name = "UserContext"; cookie.Value = userContextId.ToString(); cookie.Expires = DateTime.Now.AddDays(1); HttpContext.Current.Response.Cookies.Add(cookie); } } }if (itemsFromCsv.Count > 0) { CheckUserLogin(); DeleteItemsForCategory(); InsertItemsFromCsvLine(itemsFromCsv); }protected override void InsertItemsFromCsvLine(List<CmsProductItem> itemsFromCsvLine) { foreach (var itemFromCsvLine in itemsFromCsvLine) { try { DocumentType dt = DocumentType.GetByAlias("product"); User author = User.GetUser(0); Document doc = Document.MakeNew(itemFromCsvLine.Code, dt, author, CurrentCategoryId); doc.getProperty("productID").Value = itemFromCsvLine.ID; doc.getProperty("productAddedDate").Value = itemFromCsvLine.ItemIsNew ? DateTime.Now : DateTime.Now.AddYears(-1); doc.getProperty("productCode").Value = itemFromCsvLine.Code; doc.getProperty("productDescription").Value = itemFromCsvLine.Description; doc.getProperty("productSize").Value = itemFromCsvLine.Dimension; doc.getProperty("productRRP_AU").Value = !string.IsNullOrWhiteSpace(itemFromCsvLine.AURetail) ? itemFromCsvLine.AURetail : null; doc.getProperty("productRRP_NZ").Value = !string.IsNullOrWhiteSpace(itemFromCsvLine.NZRetail) ? itemFromCsvLine.NZRetail : null; doc.getProperty("productRRP_SG").Value = !string.IsNullOrWhiteSpace(itemFromCsvLine.SGRetail) ? itemFromCsvLine.SGRetail : null; doc.Publish(author); umbraco.library.UpdateDocumentCache(doc.Id); } catch (Exception ex) { ex.Data["currentProduct"] = itemFromCsvLine.ID; throw ex; } InsertLogger.AddLine(itemFromCsvLine.Code + " (" + itemFromCsvLine.ID + ")" + (itemFromCsvLine.ItemIsNew ? " ITEM IS NEW!" : "")); InsertLogger.AddBlankLine(2); } }But because the cookie is set in the single response umbraco hasn't picked it up and still thinks there is no auth
Hi,
The Umbraco webservices are using the validateCredentials method on the User object, maybe you can use that?
BusinessLogic.
User.validateCredentials(Login, Password)
Cheers,
Richard
Hi Richard.. using reflector it just looks like validateCredentials hits the db to check if the username and password are valid.. good check though.. ill poke around in reflector with the webservices and give it a look:
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.