As the title said, I need to raise (from the C# code behind a custom SharePoint page) a 401 error page. Any help?
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With