C# 如何在 Sharepoint 中引发 401(未经授权的访问)异常?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1599338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to raise a 401 (Unauthorized access) exception in Sharepoint?
提问by pistacchio
As the title said, I need to raise (from the C# code behind a custom SharePoint page) a 401 error page. Any help?
正如标题所说,我需要(从自定义 SharePoint 页面背后的 C# 代码)引发 401 错误页面。有什么帮助吗?
采纳答案by Rubens Farias
Try this:
尝试这个:
throw new HttpException(401, "Unauthorized access");
回答by Wout
If the exception is SharePoint related it's best to throw a SharePoint exception
如果异常与 SharePoint 相关,则最好抛出 SharePoint 异常
throw new SPException("Not Authorized");
See also http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spexception.aspx
另见http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spexception.aspx
回答by Bart Calixto
return new HttpUnauthorizedResult();