I am looking for a solution to navigate to MySite from "main" site without using a hard coded link. Also I want the same when going back to main site.

The solution is going from development to test and then to prod, so I need a way that it gets the URL and sets it as "href". The ribbon wont be shown for the end-user so I can't use this.

PS: I don't have time for using a C# solution. Prefer Javascript etc.

  • I suppose your location of mysite and root site is always the same. E.g. localhost-dev/mysite, localhost-prod/mysite so why just not take the server url and append the mysite url part? – luccio Apr 8 '15 at 13:35

There are two ways to do this

  1. One using a global JS variable (either in Master Page or js file in layouts folder). Inside this file you can have the URL and use it to form the dynamic URL
  2. Using JS code

    //Get user's personal MySite url
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', GetMySiteUrl);
    function GetMySiteUrl() {
        //Get the current user's account information
            url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=UserUrl",
            method: "GET",
            headers: {
                "accept": "application/json;odata=verbose",
            success: function (data) {
            error: function (err) {
| improve this answer | |
  • The JavaScript way works for going to MySite. But how would you go about for coming back? In what way would you call this function again from mysite and should the URL be hard coded here? Because hardcoding is what I am trying to avoid. – Fredrik Tandberg Nilsen Apr 9 '15 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.