Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 help?

like image 658
pistacchio Avatar asked Oct 21 '09 07:10

pistacchio


People also ask

What does 401 Access Denied mean?

A 401 Unauthorized Error is an HTTP status code that indicates that the server received an unverified request. In human terms, this means that the website you're trying to access won't load until you log-in with a valid user ID and password.

What is a 401 authorization required error?

The 401 Unauthorized Error is an HTTP status code error that represented the request sent by the client to the server that lacks valid authentication credentials. It may be represented as 401 Unauthorized, Authorization required, HTTP error 401- Unauthorized. It represents that the request could not be authenticated.


2 Answers

Try this:

throw new HttpException(401, "Unauthorized access");
like image 105
Rubens Farias Avatar answered Oct 16 '22 18:10

Rubens Farias


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

like image 27
Wout Avatar answered Oct 16 '22 16:10

Wout