MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

Permission level cannot be found (custom web part)

  Asked By: Harshita    Date: Jul 04    Category: MOSS    Views: 3359

This is what I'm trying to do in my custom web part when a row is selected
in an SPGridView:

-If the site exists, go to that site and do no further processing.
-If the user has the appropriate permission on the current site, create a
new site for the selected row based off a pre-defined site template.

When I attempted it as myself (an administrator), it worked great. When a
user with contributor rights tried it, he was redirected to an "Accessed
Denied" MOSS page.

To get around this, I tried two separate techniques:
1. Use advapi32.dll (Method RevertToSelf) to impersonate the App pool's
security context.
2. Use advapi32.dll (Method LogonUser) to impersonate myself (An admin).

I used each of these techniques to execute the following VB code:
Dim site As SPSite = New SPSite("CurrentSiteUrl")
site.CatchAccessDeniedException = False
Dim web As SPWeb = site.OpenWeb()
Dim spRole As SPRole = web.Roles(_Role)

On the last line of code, I receive the following exception error:
Permission level cannot be found

Does anybody have any ideas on how to resolve this?



1 Answer Found

Answer #1    Answered By: Lynette Sawyer     Answered On: Jul 04

To impersonate  the App Pool account in SharePoint you want to use the
RunWithElevatedPriveledges method. Take a look at this MSDN article. I
do this all the time to access backed databases in custom  webparts.


Didn't find what you were looking for? Find more on Permission level cannot be found (custom web part) Or get search suggestion and latest updates.