asp.net-mvc-5 – Sharepoint 2013 MVC 5提供商托管的应用程序.
过去一周我一直在敲打我的头脑,无法解决针对sharepoint提供商托管应用程序的正确身份验证的一些问题.
我目前正在为公司的Sharepoint在线开发一个sharepoint应用程序.我正在使用Visual Studio 2013.我将该应用程序部署为公司的Windows Azure门户上的云服务.一切顺利到我需要制作HttpPost的时候,然后应用程序无法进行身份验证. Conroller的设计如下: [SharePointContextFilter] public ActionResult Index() { UserSingleton user_temp = UserSingleton.GetInstance(); User spUser = null; SharePointContext spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext); using (var clientContext = spContext.CreateUserClientContextForSPHost()) { if (clientContext != null) { spUser = clientContext.Web.CurrentUser; clientContext.Load(spUser,user => user.Title,user => user.Email); clientContext.ExecuteQuery(); ....code.... } } ....code.... return View(); } 加载索引页面很顺利,操作会创建用户上下文,这一切都很好.当我尝试提交HttpPost时问题就出现了: [HttpPost] [ValidateAntiForgeryToken] [SharePointContextFilter] public ActionResult GetService(System.Web.Mvc.FormCollection fc) { PlannedHours ph = this.PopulateModel(fc); if (ph == null) return View("NoInfoFound"); ViewData["PlannedHours"] = ph; return View("Index"); } 当我通过帖子按钮拨打此电话时,我收到“无法确定您的身份.请通过启动您网站上安装的应用再试一次.” Shared / Error.cshtml视图.问题是当我删除[SharePointContextFilter]然后它工作,但这意味着请求不通过[SharePointContextFilter]因此它没有正确认证?或者是吗?因为它无法验证用户的合法性. 当我不删除[SharePointContextFilter]并调用帖子时,我注意到的一件事情,那么网址最终没有{StandardTokens}查询.是假设是这样的 – 我的意思是它像hostname.com/Home/GetService一样,但是当我使用actionlink时,spcontext.js总是将{StandardTokens}查询附加到基本URL – 像hostname.com/Home一样/ ActionNAme / SPHostUrl = HTTPS:// SHAREPOINTPAGEURL …. 我注意到的是,我调用hostname.com/Home/ActionNAme/而没有附加无法传递[SharePointContextFilter]的查询. 我是sharepoint 2013和MVC 5(Razor)的新手,所以如果你知道为什么我的HttpPost无法通过[SharePointContextFilter]尝试解释我或给出任何建议.我尝试过使用HttpGet但是,当我调用具有[SharePointContextFilter]的HttpGet并附加SPHostUrl =令牌时,它可以工作.但后来我无法使用[ValidateAntiForgeryToken].甚至在这样的应用程序中是否需要[ValidateAntiForgeryToken],因为[SharePointContextFilter]总是检查用户的合法性?我现在很困惑.网上有大量的资料可供阅读,没有什么可以解释何时附加这些标准代币,什么时候使用[SharePointContextFilter]等.事实上我第一次在我的网站上开发一个sharepoint应用程序.生活和我一直在研究和编码过去3周.所以我的知识还很有限,在回答时要记住这一点.在此先感谢,我希望我得到一些关于正在发生的事情的澄清! —————————– UPDATE ——————– ——————– 好的,快速更新.我发现了一些相当奇怪的东西. SharePointContextFilterAttribute.cs public class SharePointContextFilterAttribute : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } Uri redirectUrl; switch (SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext,out redirectUrl)) { case RedirectionStatus.Ok: return; case RedirectionStatus.ShouldRedirect: filterContext.Result = new RedirectResult(redirectUrl.AbsoluteUri); break; case RedirectionStatus.CanNotRedirect: filterContext.Result = new ViewResult { ViewName = "Error" }; break; } } } 始终返回最后一个案例(RedirectionStatus.CanNotRedirect),因为方法SharePointContextProvider.CheckRedirectionStatus(filterContext.HttpContext,out redirectUrl)包含一些我无法解决的问题. 首先: Uri spHostUrl = SharePointContext.GetSPHostUrl(httpContext.Request); if (spHostUrl == null) { return RedirectionStatus.CanNotRedirect; } 好吧我理解 – 如果httpContext.Request不包含spHostUrl它将无法重定向.出于某种原因必须存在. 但是以下内容: if (StringComparer.OrdinalIgnoreCase.Equals(httpContext.Request.HttpMethod,"POST")) { return RedirectionStatus.CanNotRedirect; } 等WHAAAT?!?不允许POST?!!?这里发生了什么?我真的不知道我做错了什么或什么?我甚至可以使用SharePointContext.cs吗?我真的需要有人来澄清到底发生了什么…我很感激! 解决方法
以上解决方案对我不起作用.我的帖子有同样的问题,但对我来说就是这个问题
return RedirectToAction("Index"); 导致错误. 我改成了: return RedirectToAction("Index",new {SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Request).AbsoluteUri}); 它起作用了. 我不确定这是你的问题的解决方案,因为你正在做返回视图,但它可能有助于某人:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – 为什么Add View List Scaffolding向导不使用
- asp.net-mvc – 将组成员身份添加到自定义成员资格/角色提供
- asp.net-mvc-3 – 如何添加html到页面里面的一个Razor if语
- asp-classic – VBScript Out of Memory Error
- asp.net-mvc – 获取视图名称,其中ViewResult.ViewName为单
- asp.net-mvc – 如何在ASP.net MVC中正确测试具有数据库调用
- asp.net-mvc – 帮助MVC身份验证/授权解决方案
- asp.net-mvc – Html.Raw()在ASP.NET MVC Razor视图
- asp.net – 如何添加jQuery UI按钮图标到输入按钮?
- asp.net – 在网页上播放mp3文件
- asp.net – 经典Asp .asp扩展页的处理程序映射在
- asp.net – 如何使用HTML5电子邮件输入类型与服务
- asp.net – “共享主机中的”LOG_BACKUP“的数据
- Asp.net MVC使用EasyNetQ操作RabbitMQ
- 如何使用asp.net WebMethod处理FormData AJAX帖子
- 创建代码生成器可以很简单:如何通过T4模板生成代
- asp.net – 403从WindowsAzure.Storage生产错误
- asp.net – 如何在volusion中编辑产品详细信息页
- asp.net-mvc – 为什么Model Binding在我的POST动
- asp.net进程中长时间运行的代码