This code runs file in the aspx file ---- "Profile" and "MasterPageFile" are defined in Web.config
<script runat="server">
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["master"] != null)
{
switch (Request["master"])
{
case "Dynamic1":
Profile.MasterPageFile = "Dynamic1.master";
  ...
Go to the complete details ...