Dear CMS Developers,
I want to set the values of custom properties of the postings created from
a
specific template programmatically. I'm using following code in
global.asax.cs:
public void CmsPosting_Creating(Object sender, CreatingEventArgs e)
{
CmsApplicationContext cmsAppContext = new CmsApplicationContext();
cmsAppContext.AuthenticateAsCurrentUser(Publi****ngMode.Update);
string GUID = CmsHttpContext.Current.Posting.Guid;
Posting posting = (Posting) cmsAppContext.Searches.GetByGuid(GUID);
if (posting.Template.SourceFile ==
"/Templates/TR/Default/News.aspx")
{
posting.CustomProperties["DAY"].Value = "8";
cmsAppContext.CommitAll();
}
}
When I'm saving a new posting, the following exception is thrown:
Login attempt failed. Access is denied.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Login
attempt failed. Access is denied.
I guess it's related with CmsApplicationContext, isn't it? Can I use
CmsHttpContext instead?
Thanks in advance,
Burak Kadirbeyoğlu