음 ... 결코 늦지 않을수록 좋습니다. 나는 오늘이 같은 문제에 부딪쳤다. 이전 의견은 원래 포스터의 표현 된 문제를 다루지 않습니다. 문제는 _Layouts 폴더에 .ASPX 페이지를 게시 한 다음 Forms 또는 Claims 인증을 사용할 때 해당 사용자 정의 페이지를 세션에서 첫 번째 히트 (이전에 기억 된 로그인이 없음)로 만듭니다. SharePoint 인증은 기본적으로 (사용자가 LayoutsPageBase 클래스에서 상속 한 경우에도) 실행되지 않습니다. 다른 SharePoint 페이지 (예 : _Layouts/15/Settings.aspx)로 이동 한 다음 다시 돌아 오면 CurrentUser 은으로 채워집니다. Reflector를 사용하여 진행 상황을보다 정확히 파악해야했습니다. 그것을 고치는 법. 당신이 CurrentUser가 == null의 경우, 당신은이 코드 줄을 추가 할 필요가 실현되면 짧은 대답입니다 : 내 경우에는
Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(new UnauthorizedAccessException());
를이 코드는 내가하는 데 사용되는 브라우저에 대한 도전/응답을 생성 로그인하고이 코드 줄 바로 뒤에 있으면 CurrentUser 개체가 올바르게 채워집니다. 여기 내 전체 기능이 다음과 같이 보입니다.
public static bool isAdminAuthorized()
{
Microsoft.SharePoint.SPContext oContext ;
Microsoft.SharePoint.SPWeb oWeb ;
Microsoft.SharePoint.SPUser oUser ;
try
{
oContext = Microsoft.SharePoint.SPContext.Current;
}
catch { throw new Exception("Can't obtain Sharepoint Context!"); }
try
{
oWeb = oContext.Web;
}
catch { throw new Exception("Can't obtain Sharepoint web!"); }
try
{
oUser = oWeb.CurrentUser;
}
catch { throw new Exception("Can't obtain Sharepoint current user!"); }
if (oUser == null)
{
Microsoft.SharePoint.Utilities.SPUtility.HandleAccessDenied(new UnauthorizedAccessException());
oUser = oWeb.CurrentUser;
}
foreach (Microsoft.SharePoint.SPGroup oGroup in oUser.Groups)
{
if (oGroup.Name.ToUpper().Contains("OWNER"))
{
return true;
}
}
return false;
}
Unfortunatelly site.CurrentUser is null입니다. – Tannheuser