Actualités développement .NET

Actualités DotNetNuke Pro et Communitaire et autres technologies mises en oeuvre par DevPCI.
02
DotNetNuke actually strip - from url when it's present in the page Name.

The Underscore _ is well allow, we'll modify a stored procedure to allow - not to be stripped.

How it works, :
Page url is build from field TabPath in Tab table in your database.

When the page is updated, the TabPath is automaticaly build running the database stored procedure named : BuildTabLevelAndPath
This stored procedure use a scalar function named RemoveStringCharacters

This scalar function use 2 parameters coming from the the stored procedure BuildTabLevelAndPath. (on is the string we treat, the other is the characters to remove.)

In SQL, left clic on the StoredProcedure, and Generate a script CREATE TO new Windows.

Save this script in case you have to go back.

In SQL, left clic on the StoredProcedure, and Generate a script DROP TO new Windows and Execute it. the stored procedure is deleted.

Modify the create script by modifing '&? ./''-#:*' to  : '&? ./''#:*'   (Delete the -)

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[BuildTabLevelAndPath](@TabId INT, @IncludeChild BIT = 0)

       AS

       BEGIN

             DECLARE @ParentId INT, @Level INT, @TabPath NVARCHAR(255), @TabName NVARCHAR(50)

             SELECT @ParentId = ParentId, @TabName = TabName FROM dbo.[Tabs] WHERE TabID = @TabId

             IF @ParentId > 0

             BEGIN

                    SELECT

                           @Level = [Level] + 1,

                           @TabPath = TabPath + '//' + dbo.[RemoveStringCharacters](@TabName, '&? ./''#:*')

                     FROM dbo.[Tabs] WHERE TabID = @ParentId

             END

             ELSE

             BEGIN

                    SELECT @Level = 0, @TabPath = '//' + dbo.[RemoveStringCharacters](@TabName, '&? ./''#:*')

             END         

             UPDATE dbo.[Tabs] SET [Level] = @Level, TabPath = @TabPath WHERE TabID = @TabId

             IF @IncludeChild = 1

             BEGIN

                    DECLARE @ChildTabs TABLE(TabID INT)

                    DECLARE @ChildID INT

                    INSERT INTO @ChildTabs SELECT TabID FROM dbo.[Tabs] WHERE ParentId =  @TabId

                    WHILE EXISTS (SELECT TOP 1 TabID FROM @ChildTabs)

                           BEGIN

                                  SET @ChildID = (SELECT TOP 1 TabID FROM @ChildTabs)

                                  EXEC dbo.[BuildTabLevelAndPath] @ChildID, @IncludeChild

                                  DELETE FROM @ChildTabs WHERE TabID = @ChildID

                           END

             END

       END

GO

Execute the script.

In the site, in host , clear the cache.

Now when updating a page with a dash - , the - will be conserved in the url.

Take care, as we have changed a little a DNN original StoredProcedure, our changes can be deleted in any dnn update who remodify this stored procedure. In this case think to redo same process.

Before changing the stored procedure :

Result :

After change of the stored procedure, and re update of the page :

Hop this help.

Next article :

#DotNetNuke 6 + 7 Replace page name space with dash in url instead of remove spaces.