How to raise a 401 (Unauthorized access) exception in Sharepoint?
As the title said, I need to raise (from the C# code behind a custom SharePoint page) a 401 error page. Any 开发者_如何学Chelp?
Try this:
throw new HttpException(401, "Unauthorized access");
If the exception is SharePoint related it's best to throw a SharePoint exception
throw new SPException("Not Authorized");
See also http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spexception.aspx
return new HttpUnauthorizedResult();
try this:
throw new UnauthorizedAccessException($"Some message");
精彩评论