SuperWasp

SuperWasp

Productivity tips, reviews, tools, software and gadgets.

 
Adding a Content Role in MWPSK
Advertisement:
Here's an easy solution to add a Content Editor role in the MyWebPagesStarterKit without defining a new role (which would take a lot of work):

Currently the authenticated user that is not part of the administrator role can do nothing more than an anonymous (unauthenticated user) user on the website.

So let's assume that those non-admin authenticated users are just content editors. We want them to be able to add/change the content of the defined section controls, without the ability to delete sections or to change the sitemap structure.

Here are the two easy steps to accomplish this:

1) Change the following in ~/Default.aspx.cs:


foreach (ISection section in _page.Sections)
{
SectionControlBaseClass ctl = (SectionControlBaseClass)LoadControl(section.UserControl);

if (User.Identity.IsAuthenticated && User.IsInRole(RoleNames.Administrators.ToString()))

Into:

foreach (ISection section in _page.Sections)
{
SectionControlBaseClass ctl = (SectionControlBaseClass)LoadControl(section.UserControl);

if ((User.Identity.IsAuthenticated))

The above change will enable the admin functions for sections on each page, whithout enabling the administration menu for administrators.


2) Change the following line in ~/SectionControls/SectionAdmin.ascx:

<asp:Button runat="server" ID="btnDeleteSection" OnClick="btnDeleteSection_Click" Text="<%$ Resources:stringsRes, glb__DeleteSection%>" CausesValidation="false" UseSubmitBehavior="false" />

Into:

<% if (Context.User.IsInRole(MyWebPagesStarterKit.RoleNames.Administrators.ToString())) {%><asp:Button runat="server" ID="btnDeleteSection" OnClick="btnDeleteSection_Click" Text="<%$ Resources:stringsRes, glb__DeleteSection%>" CausesValidation="false" UseSubmitBehavior="false" /><% } %>

The above change will remove the ability to delete section controls.

The result will enable authenticated users to update the content of the website, withouth the ability to destroy it :-)

Hope this helps!

Labels: , , , , , , , , , , ,

  Posted by oVan on Thursday, March 22, 2007 | PermaLink | 0 comments
« SuperWasp start page