Monday, December 22, 2008

DotNetNuke : Getting Portal Alias By PortalID


// using DotNetNuke.Entities.Portals;
// using System.Collections;
PortalAliasController paController = new PortalAliasController();
PortalAliasCollection paCollection = portalControler.GetPortalAliasByPortalID(PortalId);
IDictionaryEnumerator hs = paCollection.GetEnumerator();
hs.MoveNext();
PortalAliasInfo paInfo = (PortalAliasInfo)hs.Entry.Value;
string PortalAlias = paInfo.HTTPAlias;


In most of the cases when you are in Module developement, and coding in Module control, you will directly get the HTTPAlias from PortalSetting.PortalAlias.HTTPAlias.

When you are coding in a DotNetNuke page, i.e. if you have inherited an aspx page from DotNetNuke.Framework.PageBase, at that time also you will get the same property as well.

But when you are in a parent portal and you want to do redirects to child portals, at that time you can use this code.
This code can be easily modified to get all the http alias of a portal.

Wish you all happy coding with DotNetNuke :)

7 comments:

  1. Thanx's that was the answer I looking for! Needed this Code to get the HttpAlais in a Module Controller.

    ReplyDelete
  2. hi
    i try to upload my dnn from local to my server online
    but o get this error
    http://www.almny.com/Default.aspx
    Must declare the scalar variable "@PortalID".

    ReplyDelete
  3. Hey,
    It seems that your are missing something in the installation process. Please check following:
    1. connection string. Make sure you are having a right connection string in web.config at 2 places. first is at connectionstring section and secondis at app settings section.

    It seems from error that it will probably fix the error. Tell me if you need more help.

    ReplyDelete
  4. thanks
    i instal new dnn website 4.9.3
    but after i upload it i get error plz check it in this url
    http://www.almny.com/Default.aspx

    it's say
    Must declare the scalar variable "@PortalID".
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@PortalID".

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    do you know how i can solved this ?

    ReplyDelete
  5. thanks for your reply
    i dii all this steps and i still get the same error

    1- Did you upload your database to a new database server ?
    yes i did to different things
    - copy my local database and attached it on my server
    - take backup from my local database and restor it into my server
    and in both ways i get the same error

    2-Did you remember to change BOTH instances of the connection string to the database in your web.config file
    yes i did and the error reason not from connection string and i follow up all steps in the tutorials and i still get this error message

    the problem i forget my portal and say maybe i did some mistakes and i instal new website it's fresh and try to upload it and did all configration like change conection string add alias and also i get the same error message

    plz if any one have any suggestion ideas tell me it because i did erver things i can do it
    thanks for all

    ReplyDelete
  6. Hey,
    are you able to access database? if yes,
    select * from portalalias
    if its showing you your local path of installation, change it. make it like say if your domainname is mydomain.com they make it www.mydomain.com
    if you are using more than one portal or child portal you can update the query and replace localhost/dotentnuke (or any local portalalias) with your domain name without 'http://'
    Sometimes, adding a new portalalias for the portal can also help
    Hope this helps

    Regards

    ReplyDelete
  7. Replace the term @PortalID for @PortalId in the stored procedure called GetModuleByDefinition. Sorry, my english is not very good, I am from Argentina.

    ReplyDelete

Please add your valuable comments about this post if it helped you. Thanks

Popular Posts