コード例 #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException("filterContext");
            }

            var cookieAuthenticationEnabled = string.IsNullOrEmpty(WebConfigurationManager.AppSettings.Get("CookieAuthenticationEnabled")) ? false : Convert.ToBoolean(WebConfigurationManager.AppSettings.Get("CookieAuthenticationEnabled"));

            if (cookieAuthenticationEnabled)
            {
                return;
            }

            Uri redirectUrl;

            switch (SPContextHelper.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;
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: rlocus/SP-MVC
        public ActionResult Contact()
        {
            var spContext = SPContextHelper.GetSPContext(this.HttpContext);

            if (spContext != null)
            {
                SPContextHelper.ExecuteUserContextQuery <ClientContext>(spContext, (clientContext) =>
                {
                    User spUser = clientContext.Web.CurrentUser;
                    clientContext.Load(spUser);
                    Site site = clientContext.Site;
                    clientContext.Load(site);
                    Web web = clientContext.Web;
                    clientContext.Load(web);
                    return(() =>
                    {
                        ViewBag.User = new UserInformation(spUser);
                        SPPageContextInfo pageContextInfo = new SPPageContextInfo(site, web, spContext.IsWebPart);
                        if (spContext.SPAppWebUrl != null)
                        {
                            pageContextInfo.AppWebUrl = spContext.SPAppWebUrl.GetLeftPart(UriPartial.Path);
                        }
                        ViewBag.PageContextInfo = pageContextInfo;
                    });
                });
            }
            ViewBag.Message = "Contact.";
            return(View());
        }
コード例 #3
0
ファイル: AccountController.cs プロジェクト: rlocus/SP-MVC
        public ActionResult Login(string returnUrl)
        {
            if (string.IsNullOrEmpty(returnUrl))
            {
                returnUrl = "/";
            }

            var cookieAuthenticationEnabled = !string.IsNullOrEmpty(WebConfigurationManager.AppSettings.Get("CookieAuthenticationEnabled")) && Convert.ToBoolean(WebConfigurationManager.AppSettings.Get("CookieAuthenticationEnabled"));

            if (cookieAuthenticationEnabled)
            {
                Uri spHostUrl = GetSPHostUrl(returnUrl);
                if (spHostUrl == null)
                {
                    throw new Exception($"Unable to determine {SharePointContext.SPHostUrlKey}.");
                }
                return(new ChallengeResult(SPAddinAuthenticationDefaults.AuthenticationType, spHostUrl.ToString(), returnUrl));
            }
            Uri redirectUrl;
            Uri returnUri;

            if (!Uri.TryCreate(returnUrl, UriKind.RelativeOrAbsolute, out returnUri))
            {
                returnUri = null;
            }
            else
            {
                if (!returnUri.IsAbsoluteUri)
                {
                    Uri.TryCreate(HttpContext.Request.Url, returnUrl, out returnUri);
                }
            }
            switch (SPContextHelper.CheckRedirectionStatus(HttpContext, returnUri, out redirectUrl))
            {
            case RedirectionStatus.Ok:
                return(new RedirectResult(returnUrl));

            case RedirectionStatus.ShouldRedirect:
                return(new RedirectResult(redirectUrl.AbsoluteUri));

            case RedirectionStatus.CanNotRedirect:
                return(new ViewResult {
                    ViewName = "Error"
                });
            }
            return(new RedirectResult(returnUrl));
        }
コード例 #4
0
ファイル: HomeController.cs プロジェクト: rlocus/SP-MVC
        public ActionResult List(Guid listId, Guid?viewId)
        {
            var spContext = SPContextHelper.GetSPContext(this.HttpContext);

            if (spContext != null)
            {
                SPContextHelper.ExecuteUserContextQuery <ClientContext>(spContext, (clientContext) =>
                {
                    User spUser = clientContext.Web.CurrentUser;
                    clientContext.Load(spUser);
                    Site site = clientContext.Site;
                    clientContext.Load(site);
                    Web web = clientContext.Web;
                    clientContext.Load(web);
                    clientContext.Load(web.RegionalSettings);
                    clientContext.Load(web.RegionalSettings.TimeZone);

                    List list = clientContext.Web.Lists.GetById(listId);
                    View view;
                    clientContext.Load(list);
                    clientContext.Load(list.RootFolder);
                    clientContext.Load(list.Fields, fields => fields.Where(f => !f.Hidden && f.Group != "_Hidden"));
                    if (viewId == null || default(Guid) == viewId)
                    {
                        view = list.DefaultView;
                    }
                    else
                    {
                        view = list.GetViewById(viewId.Value);
                    }
                    clientContext.Load(view);
                    clientContext.Load(view.ViewFields);
                    return(() =>
                    {
                        ViewBag.User = new UserInformation(spUser);
                        ViewBag.FormDigest = clientContext.GetFormDigestDirect().DigestValue;
                        SPPageContextInfo pageContextInfo = new SPPageContextInfo(site, web, spContext.IsWebPart);
                        if (spContext.SPAppWebUrl != null)
                        {
                            pageContextInfo.AppWebUrl = spContext.SPAppWebUrl.GetLeftPart(UriPartial.Path);
                        }
                        ViewBag.PageContextInfo = pageContextInfo; ViewBag.List = new ListInformation(list, view);
                    });
                });
            }
            return(View());
        }
コード例 #5
0
ファイル: HomeController.cs プロジェクト: rlocus/SP-MVC
        public ActionResult Index()
        {
            var spContext = SPContextHelper.GetSPContext(this.HttpContext);

            if (spContext != null)
            {
                SPContextHelper.ExecuteUserContextQuery <ClientContext>(spContext, (clientContext) =>
                {
                    //PeopleManager peopleManager = new PeopleManager(clientContext);
                    //PersonProperties personProperties = peopleManager.GetMyProperties();
                    //clientContext.Load(personProperties, p => p.AccountName, p => p.PictureUrl, p => p.UserUrl,
                    //    p => p.DisplayName, p => p.Email);

                    User spUser = clientContext.Web.CurrentUser;
                    clientContext.Load(spUser);
                    Site site = clientContext.Site;
                    clientContext.Load(site);
                    Web web = clientContext.Web;
                    clientContext.Load(web);
                    clientContext.Load(web, w => w.EffectiveBasePermissions);
                    clientContext.Load(web.RegionalSettings.TimeZone);
                    return(() =>
                    {
                        ViewBag.User = new UserInformation(spUser);
                        ViewBag.FormDigest = clientContext.GetFormDigestDirect().DigestValue;
                        SPPageContextInfo pageContextInfo = new SPPageContextInfo(site, web, spContext.IsWebPart);
                        if (spContext.SPAppWebUrl != null)
                        {
                            pageContextInfo.AppWebUrl = spContext.SPAppWebUrl.GetLeftPart(UriPartial.Path);
                        }
                        ViewBag.PageContextInfo = pageContextInfo;
                    });
                });
            }
            return(View());
        }