evont-software.com
SharePoint 2019 OnPremise has still the classic MySite. To support a modern page you could build it on top of the default MySite host, but this is not the best way. With a redirect based solution you don't change anything to existing code. Just build your new MySite features on a new page on a different WebApplication and SiteCollection based on modern theme. All important links should be redirected.
To get your MySite pages redirected you face one problem. It is not only the default.aspx on MySite Host, there are several more pages especial on the user generated personal site collections. (ex. https://mysite.contoso.com/personal/<>/...)
Best solution is to use the features of IIS URL Rewrite Module. It has to be installed first on every SharePoint frontend server:
URL Rewrite Module 2.1: https://www.iis.net/downloads/microsoft/url-rewrite
Advantages:
HTTP REDIRECT
Client makes a request to http://www.contoso.com/sites/site1. IIS with ARR receives the request to http://www.contoso.com/sites/site1. ARR uses URL Rewrite to create a redirect to http://www.fabrikam.com/sites/site1, and then returns the HTTP redirect (for example, 301 or 302) to the client Client receives the redirect, and then makes a new request by using the new URL: http://www.fabrikam.com/sites/site1. SharePoint receives the request, and processes it as usual.
This scenario is SUPPORTED.
Disadvantages:
With a Http Handler you can access every request in IIS to add some custom logic.(Sample)
Code from stack overflow to demonstrate the basic solution link :
1<add name="CustomHttpModule" type="CustomHttpModule.HttpModuleImplementation, CustomHttpModule" />2using System;3using System.Web;4using System.Web.UI;5using System.Configuration;6using Microsoft.Practices.EnterpriseLibrary.Data;7using System.Data;89namespace CustomHttpModule10{11 public class HttpModuleImplementation : IHttpModule12 {13 #region IHttpModule Members1415 public void Dispose()16 {1718 }1920 public void Init(HttpApplication context)21 {22 if (context == null)23 throw new ArgumentNullException("Context == null");2425 context.AuthorizeRequest += new EventHandler(this.ProcessRequestHandler);26 }27 #endregion2829 private void DummpRequest(object sender, EventArgs e)30 {31 }32 //first check that user.identity record exist in database33 //If not then forward user to User registration page34 private void ProcessRequestHandler(object sender, EventArgs e)35 {36 try37 {38 HttpApplication context = (HttpApplication)sender;39 string strAbsoluteUri = context.Request.Url.AbsoluteUri.ToLower();40 //check if request is accessing aspx page41 if (strAbsoluteUri.Substring(strAbsoluteUri.Length - 5, 5).Contains(".aspx"))42 {43 string userName = context.User.Identity.Name;44 //replace Test Module with DB call to validate user data45 if (!CheckUserInDb(userName))46 {47 if (!strAbsoluteUri.Contains("mypage.aspx"))48 redirectToRegistrationPage(context);49 }50 }51 }52 catch (Exception ex)53 {54 }55 }56 private void redirectToRegistrationPage(HttpApplication context)57 {58 context.Response.Redirect("http://" + context.Request.ServerVariables["HTTP_HOST"].ToString() + "Regpage.aspx", false);59 }6061 private bool CheckUserInDb(string userName)62 {63 return true;64 }65 }66}
Advantages:
Disadvantages:
You also can modify each target page to add some redirect logic for example:
<meta http-equiv="refresh" content="0;url=https://sharepoint.contoso.com/Sites/Home.aspx" />
Advantages:
Disadvantages:
Following pages should be under consideration:
Title | Regex | Description |
---|---|---|
DefaultMySite | ^default.aspx | About me |
PersonMySite | person.aspx | Activities |
MyPeopleMySite | mypeople.aspx | Newsfeed entries |
Documents | personal/\w*/_layouts/15/onedrive.aspx | Onedrive documents |
Blog | personal/\w*/Blog/* | Personal blog |
Personal_Default | personal/\w*/default.aspx | Personal newsfeed |
AddApp | personal/\w*/_layouts/15/addanapp.aspx | Add apps to mysite |
Newsbweb | personal/\w*/_layouts/15/newsbweb.aspx | Create new subsites |
Sitemanager | personal/\w*/_layouts/15/sitemanager.aspx | Site Manager |
SocialSites | personal/\w*/Social/Sites.aspx | Followed sites |
FollowedDocumentsSites | personal/\w*/Social/FollowedContent.aspx | Followed documents |
SharePointHome | _layouts/15/sharepoint.aspx | Followed site activities |
Quicklinks | _layouts/15/MyQuickLinks.aspx | Quick links |
HashTags | _layouts/15/HashTagProfile.aspx | Followed HashTag Newsfeeds |
What also should work is to redirect other accounts. So we still keep url parameters (default for iis rules):
.../person.aspx?accountname=<> > .../Sites/Home.aspx?accountname=<>
You can also create a url parameter to stop redirect, if you like still have an access possibility. For example https://mysite.contoso.com/default.aspx?stopredirect=1 :
<conditions>
<add input="{QUERY_STRING}" pattern="stopredirect=1" negate="true" />
</conditions>
Here is a list of important rules:
1<rule name="Redirect_Default_MySite" stopProcessing="true">2 <match url="^default\.aspx" />3 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />4</rule>5<rule name="Redirect_Person_MySite" stopProcessing="true">6 <match url="person\.aspx" />7 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />8</rule>9<rule name="Redirect_MyPeople_MySite" stopProcessing="true">10 <match url="mypeople\.aspx" />11 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />12</rule>13<rule name="Redirect_OneDrive" stopProcessing="true">14 <match url="personal\/\w*\/_layouts/15/onedrive\.aspx" />15 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />16</rule>17<rule name="Redirect_Blog" stopProcessing="true">18 <match url="personal\/\w*\/Blog\/\*" />19 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>20</rule>21<rule name="Redirect_Personal_Default" stopProcessing="true">22 <match url="personal\/\w*\/default\.aspx" />23 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>24</rule>25<rule name="Redirect_AddApp" stopProcessing="true">26 <match url="personal\/\w*\/_layouts/15/addanapp\.aspx" />27 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>28</rule>29<rule name="Redirect_Newsbweb" stopProcessing="true">30 <match url="personal\/\w*\/_layouts/15/newsbweb\.aspx" />31 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>32</rule>33<rule name="Blocken_Sitemanager" stopProcessing="true">34 <match url="personal\/\w*\/_layouts/15/sitemanager\.aspx" />35 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent"/>36</rule>37<rule name="Redirect_SocialSites" stopProcessing="true">38 <match url="personal\/\w*\/Social/Sites\.aspx" />39 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />40</rule>41<rule name="Redirect_FollowedDocumentSites" stopProcessing="true">42 <match url="personal\/\w*\/Social/FollowedContent\.aspx" />43 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />44</rule>45<rule name="Redirect_SharePointHome" stopProcessing="true">46 <match url="_layouts/15/sharepoint\.aspx" />47 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />48</rule>49<rule name="Redirect_Quicklinks" stopProcessing="true">50 <match url="_layouts/15/MyQuickLinks\.aspx" />51 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />52</rule>53<rule name="Redirect_HashTags" stopProcessing="true">54 <match url="_layouts/15/HashTagProfile\.aspx" />55 <action type="Redirect" url="https://sharepoint.contoso.com/Sites/Home.aspx" redirectType="Permanent" />56</rule>
More documentation from Microsoft here: https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module