One of the greatest feature of DotNetNuke is to allow use to show the module in the page they like based on the viewer’s role and permission. However, this only apply to DotNetNuke generated pages. So, how about showing a module only in a page that is generated by Blog Module for example?
The solution is simple, all you need to do is add the following lines into your skin.ascx file:
<% If Regex.IsMatch (Request.URL.ToString, "REGEX HERE") Then %>
<div id="ExtraPane" runat="server"></div>
<% End If %>
The idea is to show a module pane only when a specific page is called. In the above example, we use ASP.NET Regex to match with the requested URL with the self defined Regex value “REGEX HERE”.
Using Ventrian’s Article Module for example, the default URL of a Article Page looks something like this:
http://www.example.com/NewsArticles/tabid/218/articleType/ArticleView/articleId/384/Example-Page.aspx
In the url above, we can easily identify the unique parameter of the module’s generated url: ArticleView, we use this as the Regex filter and replace it with “REGEX HERE” and you have this:
<% If Regex.IsMatch (Request.URL.ToString, "ArticleView") Then %>
If you worry you might have the word “ArticleView” word in other pages’ URL, you could put a longer regex value to filter it: &tabid=218&ArticleView=
Important Note: The “Request.URL.ToString” calls the raw url which looks like this:
Default.aspx?TabId=88&ArticleView=
Thus, your Regex Value must match with the raw url and not the Human Friendly Url that you see in the web browser.
If you do not know the raw url of the module generated page’s url, you could add this into your skin file to find it out:
<!-- <%= Request.URL.ToString %> -->
Note: <!– –> is added so that it will not show in the normal view but you can see it via browser’s view page source function. This is to avoid interference in production site.
For a live demonstration, you can see this page:
http://www.goeatout.com.my/Restaurants/Promotions.aspx and
http://www.goeatout.com.my/Restaurants/Promotions/Details/View/PID/31315/Hong-La-Qiao-Restaurant-Steamboat-Buffet.aspx
In the second link, a module “More Related Dining Promotions” is added at the page bottom which only shows in the page with “PID” in the URL but not in any of it’s parent page /Promotions/
For advanced combination, you could add “AND” in the code:
<% If Regex.IsMatch (Request.URL.ToString, "REGEX HERE") AND DotNetNuke.Security.PortalSecurity.IsInRoles(PortalSettings.AdministratorRoleName) Then %>
<div id="ExtraPane" runat="server"></div>
<% End If %>
In the example above, it will show the extra pane only if the request url is match with your regex and the viewer has administrator role.
Have fun^^