Creating Page Redirects in SharePoint 2013



Hello everyone, sorry for my absence from the blog. Lots of stuff happening both with work and in my personal life. Also going through some of my plans for the future and what certifications I need for that future. Anyway I’m here to talk a little bit about SharePoint! I’ll wait for you to wake from the happiness coma.

Specifically we are going to be talking about page redirection in SharePoint 2013 hosted on Office 365. I am creating a SharePoint website for our customers to come login and edit and view their documents. Our internal customer service people will have the ability to login and see all the customer’s libraries and have some global assets as well.

My goal was to make one URL people can go to since we are not dealing with SharePoint and not a regular web server setting up a page redirection is out. I had to think creatively with this project because we have numerous customers and I need to be able to see who it is that’s logged into the site and be able to redirect those customers to their appropriate libraries.

First things first we start by creating our site and setting up our prerequisites. With that we log into our site and from the top options icon we select Site Settings -> People and Groups, There we are displaying all of our groups. If we look at the URL we see at the end a variable called GroupId it will usually show something like GroupId=50 change the value to 0. We do that so that we display our top level group which will display all of our users. We want to get the userId for the user, if you hover over the user the link in the corner will display the userId. Take note of it.

Next step is to navigate back to our site’s home page. Using Office 365’s web editor we select Edit Page in the top left. Click Add web Part -> Script Editor. We add in some JavaScript to our snippet:

if (_spPageContextInfo.userId == 49) {
     window.location ="‌aspx";

Sharepoint 2013 uses an awesome object called _spPageContextInfo that makes doing something like this incredibly easy. It can pull a myriad of information from the Sharepoint site and the user that is logged in. To see more information check this out.

It’s simple JavaScript but it makes my life so much easier.Now that I have the script firing my customers are being redirected to their own subsites. I now have one URL for everyone using the site. Life is good!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply