我正在MVC 4.5中构建一个小应用程序.我有一个Azure数据库,我首先使用代码框架来设置代码.该应用程序托管在我的开发sharepoint区域.
Home控制器的Index()Action包含[SharePointContextFilter]和加载登录用户的用户名等.调试应用程序并运行第一个操作时,Sharepoint {StandardTokens}将附加到url,因此SPHostUrl和AppWebUrl其他一些变量将添加到查询字符串中.
如果我导航离开一个动作没有[SharePointContextFilter]正常工作,直到我导航回动作用的[SharePointContextFilter].然后我得到一个错误说:
Unknown User
Unable to determine your identity. Please try again by launching the app installed on your site.
Run Code Online (Sandbox Code Playgroud)
我假设这是因为{StandardTokens}缺少一些Sharepoint ,因为如果我手动将它们附加到链接,如下所示:
@Url.Action("Index", "Home", new { SPHostUrl = SharePointContext.GetSPHostUrl(HttpContext.Current.Request).AbsoluteUri })
Run Code Online (Sandbox Code Playgroud)
并用它标记其他动作[SharePointContextFilter],它仍然有效.
Hovever这似乎是解决这个问题的一种不必要的复杂方法.我不想在我的应用程序中标记每个动作[SharePointContextFilter],并{StandardTokens}为我创建的每个链接手动插入查询字符串.不应该以某种方式将此信息保存到会话或cookie中,所以我不必这样做吗?
供参考,这里有一些代码:
HomeController.Index(),第一个运行的Action.
[SharePointContextFilter]
public ActionResult Index()
{
User spUser = null;
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{ …Run Code Online (Sandbox Code Playgroud)