Using feature stapling, I have created custom code that attaches a new master page as well as adds a webpart to a default page for sites of the type Community. It worked fine in my dev environment, but when I moved it to my model environment and tried to create a site collection, it failed. I ended up finding out it was because in dev we had Security Validation off but it is on in model. The bizarre thing I'm running into, however, is that the feature itself is not where the error happens. The code runs all the way through in my feature without any issues at all, but when it tries to activate the "BaseWeb" feature, that's where I get the following error:
The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
Again, this error does not appear for the feature I added, but shows up when the BaseWeb feature is being activated. However, if I remove my solution that staples my feature to the community template, no such error occurs and the community site gets created totally fine. So, I know it has to have something to do with my solution, but at the same time I'm not getting any errors within my solution itself.
The feature also works fine if I manually enable it instead of it being automatically enabled when the site is created.
Lastly, my code sets "AllowUnsafeUpdates" to true at the very beginning of it and then sets "AllowUnsafeUpdates" to false at the very end.
Thank you so much in advance for any help you can offer!
EDIT: If I comment out the AllowUnsafeUpdates part that sets it to false at the end, I don't get any errors and it works, but from my understanding if I set it to true I need to set it to false at the end of the FeatureActivated function.
EDIT 2: For anyone curious, I actually didn't need to "AllowUnsafeUpdates" anyway for the last part of my code so I set it to false earlier and ended up not having any issues. Thanks anyway!