Installing ASP.NET 2.0 Application -ensure that it runs ASP.Net 2.0

For my Web Setup (created by MS Visual Studio Setup Project)  I wanted to ensure that a new web application runs ASP.Net 2.0.

Pointed by this thread, I downloaded  IIS Chameleon“.

I’ve changed the assembly toDLL, excluded Non GUI classes, made ASPNetVersion,INETMGRHelper and CURRENT_RUNTIME_VERSION public and also changed definitions.xml to be embedded resource(may be not a good idea, because it will not allow to customize, but easier to distribute).

I also changed GetAllASPNETVersions to read from ResourceStream.

            Assembly asm = Assembly.GetExecutingAssembly();
            Stream stream1 = StreamHelper.GetManifestResourceStream(APP_DEFINITIONS_FILENAME,asm );//definitions.xml
            document.Load(stream1);//APP_DEFINITIONS_FILENAME);
 

Now my installer custom action calls the function

   Sub EnsureIISAppVer2(ByVal VDir As String, ByVal Site As String, ByVal Port As String)

        ‘ map IISSite to Site

        Trace.WriteLine(“EnsureIISAppVer2 VDir “ & VDir & ” Site “ & Site & ” Port “ & Port)

        Dim oVdir As New IISChameleon.IISVirtualDir()

        oVdir.MetabasePath = Site & “/root/” & VDir ‘Site has format @”/LM/W3SVC/1″;

        oVdir.ASPNetVersion = IISChameleon.INETMGRHelper.CURRENT_RUNTIME_VERSION

        Dim helper As New IISChameleon.INETMGRHelper()

        helper.DoAspnetRegistration(oVdir)

     End Sub

 

 

Advertisements

DotNetNuke error reporting requires improvement

I found that DotNetNuke code often doesn’t report exceptions to user, but hides them.This style of error handling is natural for VB developers, who had the favorite comand “on error resume next”.(I hope that DNN developers are from different school).


 In some cases, exception are written it to EventLog table, but it is not always easy to access. E.g. if errors are occured during install and portal is not created yet, View log Web UI obviously is not available.


I’ve posted the suggestion to DNN support.
Below I listed places where I’ve added exception reporting. I am going to add more as far I will find reporting missing, but useful for my debugging.


In Upgrade.InstallDNN


                ‘After Parse the script nodes


              If Len(strExceptions) > 0 Then ‘mnF 12/4/2006


                    HtmlUtils.WriteFeedback(HttpContext.Current.Response, 0, “Exceptions were reported to Default Data Provider log file”)


                    strExceptions = “” ‘reset


                End If


  ‘And After installMemberRole


                If Len(strExceptions) > 0 Then ‘mnF 12/4/2006


                    HtmlUtils.WriteFeedback(HttpContext.Current.Response, 0, strExceptions)


                    strExceptions = “” ‘reset


                End If


 


In LibraryComponentsPortalPortalController.vb AddPortalInfo


In catch added Trace exception


 


 


In DNNLibraryComponentsProvidersLoggingException LoggingExceptionLogController.vb


  Sub AddLog(ByVal objException As Exception, ByVal LogType As ExceptionLogType)


            Trace.WriteLine(“DotNetNuke.Services.Log.EventLog.ExceptionLogController.AddLog: “ & LogType.ToString() & ” – “ & objException.ToString())


 


In DNNLibraryComponentsUpgradeUpgrade.vb


‘InstallMemberRoleProvider should save to log any exceptions (if any) in the same way as Upgrade.ExecuteScript does


            If Len(strExceptions) > 0 Then ‘mnf 13/4/2006


                FSHelperLib.StreamHelper.SaveStringToFile(strExceptions, strProviderPath & “InstallMemberRoleProvider.log”)


            End If


 


In DNNLibraryComponentsUsersUserController.vb


Function AddUser


                If Status = UserRegistrationStatus.AddUser Then


‘Existing code removed for brevity


                Else ‘mnf 13/4/2006


                    If UserId < 0 Then ‘TODO may be throw exception


                        Trace.WriteLine(“Unable to AddUser “ & objUser.Membership.Username & ” – “ & Status.ToString())


                    End If


                End If


 


 Function DeleteAllUsers


Catch exc As Exception
                Trace.WriteLine(exc.ToString())


InstallInstall.aspx.vb Function InstallApplication


‘After backing up old web.config
                Catch ex As Exception
                    ‘Error backing up old web.config
                    ‘This error is not critical, so can be ignored
                    System.Diagnostics.Trace.WriteLine(“InstallApplication ” & backupFolder & “web_old.config” & ” error ” & ex.ToString()) 
                End Try


DNNLibraryComponentsSecurityRolesRoleController.vb AddUserRole
                Try
                    AspNetSecurity.Roles.AddUserToRole(objUser.Membership.Username, objUserRole.RoleName)
                Finally ‘instead of Catch ex As Exception
                   
‘Reset the Application Name
    
                    
Common.Globals.SetApplicationName(originalAppName)
                End Try


DNNLibraryComponentsTabsTabController.vb Function GetTab


            Try


                Return FillTabInfo(dr)


            Catch exc As Exception


                System.Diagnostics.Trace.WriteLine(“ComponentsTabsTabController.vb GetTab “ & TabId & ” error “ & exc.ToString())


            Finally


                If Not dr Is Nothing Then


                    dr.Close()


                End If


            End Try


            Return Nothing


DNNLibraryComponentsSkinsSkin.vb in Page_Init


                Dim arrModuleControls As ArrayList = objModuleControls.GetModuleControlsByKey(Key, objModule.ModuleDefID)


                If arrModuleControls.Count = 0 Then


                    System.Diagnostics.Trace.WriteLine(“DotNetNuke.UI.Skins.Skin.Page_Init GetModuleControlsByKey returned 0 controls for key “ & Key)


                End If


DNNLibraryControlsDotNetNuke.WebUtilityClientAPI.vb GetClientAPICapsDOM


Try


                    strFileName = System.Web.HttpContext.Current.Server.MapPath(ScriptPath & “/ClientAPICaps.config”)


                Catch ex As Exception


                    System.Diagnostics.Trace.WriteLine(“DotNetNuke.UI.Utilities.ClientAPIs.GetClientAPICapsDOM “ & ex.ToString())


                    ‘ignore error – worried about people with reverse proxies and such…


                End Try


NEW for DNN 4.4.
LibraryProvidersMembershipProvidersAspNetMembershipProviderAspNetMembershipProvider.vb  CreateUser


Catch exc As Exception ‘ an unexpected error occurred

LogException(exc)  ‘ WHY it is COMMENTED?????????

createStatus = UserCreateStatus.UnexpectedError


End Try

NEW for DNN 4.4.
adminSecuritySendPassword.ascx.vb  cmdSendPassword_Click


                            Try


                                objUser.Membership.Password = UserController.GetPassword(objUser, txtAnswer.Text)


                            Catch ex As Exception


‘Actual exception should be logged


                                canSend = False


                                strMessage = Localization.GetString(“PasswordRetrievalError”, Me.LocalResourceFile)


                            End Try


AND


                              Try


                                Mail.SendMail(objUser, MessageType.PasswordReminder, PortalSettings)


                                strMessage = Localization.GetString(“PasswordSent”, Me.LocalResourceFile)


                            Catch ex As Exception


‘Actual exception should be logged


                               

canSend =
False

                            End Try


C:ProjectsFuncSolnDNNLibraryComponentsFrameworkPageBase.vb PageCulture
Try
preferredLocale = HttpContext.Current.Request(“language”)


…code is omitted


Catch
‘Actual exception should be logged

End Try


 

Data change checking features in DotNetNuke pages.

I’ve used  data change checking features  described by Eric Woodruff in my ASP.NET application. When I converted the ASP.NET application to DotNetNuke, I still needed to have the same functionality.


Unfortunately .Net doesn’t allow multiple inheritanse,  so I had to re-factor EWSoftware.Web.BasePage.


I created an interface IDataChangeChecking, that described the public methods, relevant to data change checking:
//described in http://www.codeproject.com/aspnet/EWSWebPt2.asp
string
[] BypassPromptIds
bool CheckForDataChanges
bool Dirty
string[] SkipDataCheckIds
StateBag ControlViewState
//expose protected ViewState


and created public class DataChangeCheckingImpl with methods extracted from original BasePage






{
// Methods
public DataChangeCheckingImpl(Control owner);
public static void BypassChangesNotSavedPrompt(Control container, string ClientID);
public static void BypassChangesNotSavedPromptIDs_Add(Control container, string[] ClientIDs);
public void OnInit(EventArgs e);
public void OnPreRender(EventArgs e);
public static void SetCheckForDataChanges(Control container, bool value);
public static bool SetPageDirty(Control container, bool Value);
public static void SkipDataChangesCheckIDs_Add(Control container, string[] ClientIDs);

// Properties
public string[] BypassPromptIds { get; set; }
public bool CheckForDataChanges { get; set; }
public string ConfirmLeaveMessage { get; set; }
public bool Dirty { get; set; }
private HttpRequest Request { get; }
public string[] SkipDataCheckIds { get; set; }
public StateBag ViewState { get; }

// Fields
private bool bIsDirty;
private Control m_ctlOwner;
private IDataChangeChecking m_IDataChangeChecking;
}


Finally I’ve created DataChangeCheckingDefaultPage class, derived from DotNetNuke.Framework.CDefault and implementing IDataChangeChecking interface.


Additionaly OnInit event handler created DataChangeCheckingImpl object and methods
DataChangeCheckingImpl.OnInit and OnPreRender are called from the corresponding DataChangeCheckingDefaultPage event handlers.

Now I can configure data editing DotNetNuke modules, that user will see warning if he/she try to exit without saving data. 

Function to Print DirectoryEntry properties

When I debugging function that retrieved active directory properties, Visual Studio 2005 debugger show them as a collection , but not as an individual values. So I wrote function, copied from GetPropertyList function from LDAP, IIS and WinNT Directory Services  article written by


            [Conditional(“DEBUG”)]


            public static void PrintDirectoryEntryProperties(System.DirectoryServices.DirectoryEntry entry, string sComment)


       


            // loop through all the properties and get the key for each


            foreach (string Key in entry.Properties.PropertyNames)


            {


                string sPropertyValues = String.Empty;


                // now loop through all the values in the property;


                // can be a multi-value property


                foreach (object Value in entry.Properties[Key])


                    sPropertyValues += Convert.ToString(Value) + “;”;


                // cut off the separator at the end of the value list


                sPropertyValues = sPropertyValues.Substring(0, sPropertyValues.Length – 1);


                // now add the property info to the property list


                Debug.WriteLine(Key + “=” + sPropertyValues);


            }


        }


Ideally it should be possible to write  Debug Visualizer for them. 



 

Visual Studio VS 2005 doesn’t start debugging of Web Server.

A few times when I re-start debugging of my ASP.NET application from VS 2005 I received


“Unable to start debugging on the Web Server. The operation has timed out”.


I had to restart IIS to fix the error. Not sure what causes this.

Setup of new version using .Net 2.0 causes System.BadImageFormatException

I had a .Net 1.1 application with Setup project and RemovePreviousVersions=true.


After I converted it to .Net 2.0, I’ve tried to install it on machine where previous version was installed.


It caused System.BadImageFormatException exception. I believe that new .Net 2.0 Setup failed to uninstall .Net 1.1 application due to .Net framework versions mismatch.


I’ve desided to change UpgradeCode, that will be considered as new application, and it allowed me to install new version.


Alternatively user can manually uninstall previous version prior to install new one(not tested yet).
I’ve reported the issue toMicrosoft.

Emailable DotNetNuke Module

I’ve used an e-Mailable ASP.Net web page described by Eric Woodruff in an ASP.NET application. When I converted the ASP.NET application to DotNetNuke, I still wanted to have the same functionality-ability to e-mail rendered content of the DotNetNuke module.

I created the class EmailableModule based on DotNetNuke.Entities.Modules.PortalModuleBase and copied and paste the content of EMailPage class. There are a few places where I changed references to page to references to DNN module.I was able to use helper Event and Exception classes from the original EMailPage without changes.

Now I can use the same class derived from EmailableModule in DNN application and in generated e-mails.

Related Links: As an alternative to Eric Woodruff‘s solution see Scott Mitchell‘s:  

  • Emailing the Rendered Output of an ASP.NET Web Control
  • Enhancing the ‘Email the Rendered Output of an ASP.NET Web Control’ Code
  • Emailing the Rendered Output of an ASP.NET Web Control in ASP.NET 2.0