We are experiencing a problem with Url Master 1.15.1 and DNN 5.2.2.
If a url is entered that refers to a tab on a different portal, the following error appears:
500 Server Error
An error occured during processing : if possible, check the event log of the server
Exception:
Object reference not set to an instance of an object.
Stack Trace:
at DotNetNuke.Entities.Portals.PortalSettings..ctor(Int32 tabID, PortalAliasInfo objPortalAliasInfo) in F:\dnn_05.02.02\Library\Entities\Portal\PortalSettings.vb:line 149 at iFinity.DNN.Modules.UrlMaster.DNNFriendlyUrlProvider.ImprovedFriendlyUrlWithMessages(TabInfo tab, String path, String pageName, String httpAlias, Boolean ignoreCustomRedirects, FriendlyUrlSettings settings, List`1& messages) at iFinity.DNN.Modules.UrlMaster.DNNFriendlyUrlProvider.ImprovedFriendlyUrl(TabInfo tab, String path, String pageName, String httpAlias, Boolean ignoreCustomRedirects, FriendlyUrlSettings settings) at iFinity.DNN.Modules.UrlMaster.UrlRewriteModule.CheckForRedirects(Uri requestUri, NameValueCollection queryStringCol, UrlAction result, String requestType, FriendlyUrlSettings settings) at iFinity.DNN.Modules.UrlMaster.UrlRewriteModule.ProcessRequest(HttpContext context, HttpRequest request, HttpServerUtility Server, HttpResponse response, Boolean useFriendlyUrls, String requestType, Uri requestUri, UrlAction result, NameValueCollection queryStringCol, FriendlyUrlSettings settings)
My expectation would be that the url should be ignored and the browser remain on the current page if an invalid tab is entered.
For example, if you enter "/default.aspx?tabid=123456789" it is handled in a user friendly way and just ignored. The browser remains on the current tab.
However, if you enter a url for a tab that exists in different portal (e.g. "/default.aspx?tabid=802" on our site) you get the exception.
I have had a look at the code in reflector and can see where the problem lies....
Let's look at the ImprovedFriendlyUrlWithMessages method in the DNNFriendlyUrlProvider class
public static string ImprovedFriendlyUrlWithMessages(TabInfo tab, string path, string pageName, string httpAlias, bool ignoreCustomRedirects, FriendlyUrlSettings settings, out List<string> messages)
{
string friendlyAlias = path;
friendlyAlias = GetFriendlyAlias(path, httpAlias);
friendlyAlias = GetFriendlyQueryString(tab, friendlyAlias, pageName, settings);
PortalAliasInfo portalAlias = new PortalAliasController().GetPortalAlias(httpAlias, tab.get_PortalID());
PortalSettings portalSettings = new PortalSettings(tab.get_TabID(), portalAlias);
friendlyAlias = ImproveFriendlyUrlWithMessages(tab, friendlyAlias, pageName, portalSettings, ignoreCustomRedirects, settings, out messages);
return ForceLowerCaseIfAllowed(tab, friendlyAlias, settings);
}
The problem occurs when the PortalID in the tab parameter is different from the portal referred to by the httpAlias. This results in portalAlias being set to null.
PortalAliasInfo portalAlias = new PortalAliasController().GetPortalAlias(httpAlias, tab.get_PortalID());
This of itself is not a problem, but the following line is the problem since it attempts to instantiate portalSettings with a null portalAlias.
PortalSettings portalSettings = new PortalSettings(tab.get_TabID(), portalAlias);
This causes a NullReferenceException within the PortalSettings constructor as can be seen below:
Public Sub New(ByVal tabID As Integer, ByVal objPortalAliasInfo As PortalAliasInfo)
_ActiveTab = New TabInfo
PortalId = objPortalAliasInfo.PortalID ' *** exception thrown here because objPortalAliasInfo is null
PortalAlias = objPortalAliasInfo
Dim controller As New PortalController
Dim portal As PortalInfo = controller.GetPortal(PortalId)
If Not portal Is Nothing Then
GetPortalSettings(tabID, portal)
End If
End Sub
So, my request is can the DNNFriendlyUrlProvider be updated to handle urls that point to tabs in different portals in a user-friendly way.
Is this a suitable request or am I missing something in the above examples?
Thanks,
Jonathan