I think you can do that, but why wouldn't you simply create a module and skip all the extra coding?
To create a module you need:
1. an XML template file with a .dnn extension
2. a web control
3. Zip it and upload it as a module to your dotnetnuke site.
I was trying to figure out the same thing, then I found the site http://www.dnnwiki.net. This is for creating c# modules, but it's very simple. Download the WhoAreYou.zip file to look at these files. This guy did an AMAZING job.
Example whoareyou.dnn
<dotnetnuke version="3.0" type="Module">
<folders>
<folder>
<name>WhoAreYou</name>
<description>Says who is logged in and which Security Roles they belong</description>
<version>01.01.01</version>
<modules>
<module>
<friendlyname>Who Is Logged in Module</friendlyname>
<controls>
<control>
<title>View WhoAreYou</title>
<src>WhoAreYou.ascx</src>
<type>View</type>
</control>
</controls>
</module>
</modules>
<files>
<file>
<name>WhoAreYou.ascx</name>
</file>
<file>
<name>WhoAreYou.ascx.cs</name>
</file>
</files>
</folder>
</folders>
</dotnetnuke>
Example WhoAreYou.ascx
<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="WhoAreYou.ascx.cs" Inherits="WhoAreYou" %><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
Example WhoAreYou.ascx.cs
public partial class WhoAreYou : DotNetNuke.Entities.Modules.PortalModuleBase
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
DotNetNuke.Entities.Users.OnlineUserInfo mRoles = new DotNetNuke.Entities.Users.OnlineUserInfo();
DotNetNuke.Security.Roles.RoleController mUserRoles = new DotNetNuke.Security.Roles.RoleController();
DotNetNuke.Entities.Users.UserInfo mUser = new DotNetNuke.Entities.Users.UserInfo();
mUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
string showRoles = "";
foreach (string i in mUserRoles.GetRolesByUser(mUser.UserID, mRoles.PortalID))
{
showRoles += i.ToString() + ", ";
}
Label1.Text = "Logged in as: " + mUser.Username + "<br>Roles: " + showRoles.ToString();
}
catch (Exception err)
{
Label1.Text = "Note: User info failed";
}
}
}