Mono Support Extending Modules in ASP.NET Framework 4 

Viewed 39273 time(s), 14 post(s), 6/29/2015 2:42:28 PM - by swalsh
6/29/2015 2:42:28 PM
70 Reputation 10 Total posts

Hi, sorry for the novice question, but I having a heck of time extending the Login Module for my own customization.   What should be trivial task is becoming a frustrating endeavor.  All I want to do is redirect the user upon login to a custom page.  I have looked at the examples online and have come up with the following.    It compiles fine but when I go to the login page I just get the "Error An error has occured in the application." page.  I am not able to find the error entry in the system log files and I can not find if or where the error is being logged in the MonoX Framework.



Here is my ascx page.   I bolded the only changes I made to the LoginModule.ascx.    Note that I had to change the 'CodeBehind=" declaration to CodeFile= as it would not compile with the CodeBehind in there.

01.<%@ Control
02.    Language="C#"
03.    AutoEventWireup="true"
04.    Inherits="YourNamespace.myLoginModule"
05.    CodeFile="LoginModule.ascx.cs" %>
06.    <%@ Register Src="/MonoX/Controls/MonoX.Controls.ValidationHandler/ValidationHandler.ascx" TagPrefix="monox" TagName="ValidationHandler" %>
07. 
08.<%@ Import Namespace="MonoSoftware.MonoX.Resources"  %>
09. 
10.<monox:ValidationHandler id="validationHandler" runat="server" ValidationGroup="<% $Code: this.ValidationGroup %>"></monox:ValidationHandler>
11. 
12.<div class="login-module">
13.    <dl>
14.        <dd runat="server">
15.            <asp:ValidationSummay ID="validationSummaryLogin" runat="server" DisplayMode="BulletList" CssClass="validation-summary" ValidationGroup="Login" />
16.        </dd>
17.    </dl>
18.    <asp:Panel runat="server" ID="pnlLoginContainer" Width="100%">
19.        <asp:Login ID="ctlLogin" runat="server" Width="100%" >
20.            <LayoutTemplate>
21.                <!--<div class="login-headline">
22.                    <h5><%# MonoSoftware.MonoX.Resources.DefaultResources.Login_Title%></h5>
23.                </div>-->
24.                <div class="login-user-name jq_FieldValidatorWrapper">
25.                    <asp:Label ID="lblUserName" CssClass="inline-label" AssociatedControlID="UserName" runat="server" Text='<%# MonoSoftware.MonoX.Resources.DefaultResources.Login_UserName %>'></asp:Label>
26.                    <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
27.                    <asp:RequiredFieldValidator ID="vldRequiredUserName" runat="server" ControlToValidate="UserName" Text="!" SetFocusOnError="true" ValidationGroup="Login" CssClass="validator" Display="Dynamic" ErrorMessage="<%# String.Format(MonoSoftware.MonoX.Resources.DefaultResources.ValidationMessage_RequiredField, MonoSoftware.MonoX.Resources.DefaultResources.Global_UserName) %>" />
28.                </div>
29.                <div class="login-password jq_FieldValidatorWrapper">
30.                    <asp:Label ID="lblPassword" CssClass="inline-label" AssociatedControlID="Password" runat="server" Text='<%# MonoSoftware.MonoX.Resources.DefaultResources.Login_Password %>'></asp:Label>
31.                    <asp:TextBox runat="server" ID="Password" TextMode="Password"></asp:TextBox>
32.                    <asp:RequiredFieldValidator ID="vldRequiredPassword" runat="server" ControlToValidate="Password" Text="!" SetFocusOnError="true" ValidationGroup="Login" CssClass="validator" Display="Dynamic" ErrorMessage="<%# String.Format(MonoSoftware.MonoX.Resources.DefaultResources.ValidationMessage_RequiredField, MonoSoftware.MonoX.Resources.DefaultResources.Global_Password) %>" />
33.                </div>
34.                <div class="offset">
35.                    <asp:CheckBox runat="server" ID="RememberMe" />
36.                    <asp:Label ID="lblRememberMe" AssociatedControlID="RememberMe" runat="server" Text='<%# MonoSoftware.MonoX.Resources.DefaultResources.Login_RememberMe %>'></asp:Label>
37.                </div>
38.                <div class="login-buttons">
39.                    <div class="login-buttons-holder">
40.                        <MonoX:StyledButton ID="Login" CommandName="Login" CssClass="regular-button" runat="server" Text='<%# MonoSoftware.MonoX.Resources.DefaultResources.Login_Login %>' ValidationGroup="Login"></MonoX:StyledButton>
41.                        <asp:HyperLink ID="lnkRegister" CssClass="regular-button" runat="server" NavigateUrl='<%# MonoSoftware.MonoX.Utilities.LocalizationUtility.RewriteLink(RegisterPageUrl) %>'><%= MonoSoftware.MonoX.Resources.DefaultResources.Login_Register %></asp:HyperLink>
42.                        <asp:HyperLink ID="lnkForgotPassword" runat="server" NavigateUrl='<%# MonoSoftware.MonoX.Utilities.LocalizationUtility.RewriteLink(PasswordRecoveryPageUrl) %>'><%= MonoSoftware.MonoX.Resources.DefaultResources.Login_PasswordRecoveryText%></asp:HyperLink>
43.                    </div>
44.                </div>
45.            </LayoutTemplate>
46.        </asp:Login>
47.    </asp:Panel>
48.</div>


And here is my codefile.  It was literally cut and pasted from an example I saw online.
01.using System;
02.using System.Collections.Generic;
03.using System.Linq;
04.using System.Web;
05.using MonoSoftware.MonoX.Controls;
06.using MonoSoftware.MonoX.Repositories;
07.using MonoSoftware.MonoX.DAL.EntityClasses;
08.using MonoSoftware.MonoX.Utilities;
09. 
10.using MonoSoftware.MonoX;
11.using MonoSoftware.MonoX.API;
12. 
13./// <summary>
14./// Summary description for myLoginModule
15./// </summary>
16.///
17.namespace YourNamespace
18.{
19.public partial class myLoginModule : MonoSoftware.MonoX.ModuleGallery.LoginModule
20.    {
21.        public override void RedirectAfterLogin()
22.        {
23.                Response.Redirect("htt://company1.sitename.domain");       
24.        }
25.    }
26. 
27.}


Any idea what I am doing wrong?  Your help is appreciated.

1
6/29/2015 5:44:34 PM
70 Reputation 10 Total posts

Found a log file entry if it helps...

2015-06-29 13:37:27,447 [10] ERROR MonoX [10.0.0.213] - Error
System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoSoftware.MonoX.ModuleGallery.LoginModule.OnInit(EventArgs e)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

2
6/30/2015 1:28:45 PM
3016 Reputation 428 Total posts

Hi,

you can find more details here.

Regards.

3
6/30/2015 4:46:18 PM
70 Reputation 10 Total posts

Hi imarusic, 

Yes..I saw that article and have done the steps exactly as prescribed.   I don't see any difference between my custom class and the one in the article, except mine deals with the LoginModule in the Modules folder.  My code is not even being hit in the debugger, and I still get the Object reference not set to an instance of an object error.    I can't put my finger on what is wrong.  This should be about as simple as it gets.   I even tried this on a fresh install using 5-1-40-5150.

Here is my class (cstLoginModule.ascx.cs):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MonoSoftware.MonoX.Extensions;
using MonoSoftware.MonoX.ModuleGallery;

/// <summary>
/// Summary description for cstLoginModule
/// </summary>

namespace MyCustom
{


    public partial class cstLoginModule : MonoSoftware.MonoX.ModuleGallery.LoginModule
    {
        public override void RedirectAfterLogin()
        {
            Response.Redirect("http://www.google.com");
        }
    }
}


And here is the top of the cstLoginModulePage (cstLoginModule.ascx):  Everything else was copy/pasted from the existing LoginModule.ascx page.
<%@ Control 
    Language="C#" 
    AutoEventWireup="true" 
    Inherits="MyCustom.cstLoginModule"
    CodeFile="cstLoginModule.ascx.cs" %>
    <%@ Register Src="/MonoX/Controls/MonoX.Controls.ValidationHandler/ValidationHandler.ascx" TagPrefix="monox" TagName="ValidationHandler" %>

And here is how I am calling the new login module in Login.aspx:
<%@ Register TagPrefix="MonoX" TagName="Login" Src="/MonoX/ModuleGallery/cstLoginModule.ascx" %>


Everything compiles fine but I get the error when I hit the Login.aspx page.  This should be so simple, do you see what else I should do or how to fix this?

Thanks
Shawn

4
7/1/2015 2:26:22 PM
2218 Reputation 300 Total posts

Try deleting the designer file and regenerating it.

Regards

5
7/2/2015 12:48:03 AM
70 Reputation 10 Total posts

Thanks but there is no designer file on the usercontrol to delete.  Can anyone tell me how to get my class file working?  I've followed every example, even downloaded the CustomMembershipEditor User Control and put it in my site.   Even it gets the object reference not found error when I try to use it on a page.
It seems that there are many 'examples' but they are old and do not work in .net framework 4.  So, I am getting to the point where I cannot consider MonoX for at least 3 projects that clients want as I cannot get this very simple question answered.   I'm about ready to offer a bounty to anyone who can get me a *working* example.

Thanks

6
7/2/2015 8:12:03 AM
3016 Reputation 428 Total posts

Hi,

there is abviously something wrong if you do not have a designer file. All you have to do is to create custom control, set base class and markup. I've attached an example.

I also received an error(for this test example), but it was related to Styled button registration and fixed fast(different error from the one you posted.). 

I hope this helps,

Regards.

7
7/2/2015 10:08:54 AM
145 Reputation 18 Total posts

Hi,

please note that you should set YOUR code behind name in markup:

<%@ Control Language="C#" AutoEventWireup="true" Inherits="YourNamespace.myLoginModule" CodeFile="myLoginModule.ascx.cs" %>

Regards.

8
7/2/2015 12:03:59 PM
70 Reputation 10 Total posts

Hi imarusic,

Thank you for the sample control.   I unzipped it and dropped it in the ModuleGallery folder of a brand new, untouched instance of 5-1-40-5150.  I ran this using IIS Express in Win8.  I am running .net Framework 4, integrated.   I had to change the CodeBehind="Test1.ascx.cs" to CodeFile="Test1.ascx.cs" in Test1.ascx as it would not compile.  

I went to Login.aspx and deleted   <MonoX:Login runat="server" ID="ctlLogin" Width="100%" /> and dragged the new Test1.ascx control in its place, so it looks like this  <MonoX:Test1 runat="server" ID="ctlLogin" Width="100%"/>.

  I also have <%@ Register Src="/MonoX/ModuleGallery/Test1.ascx" TagPrefix="MonoX" TagName="Test1" %> at the top of the page.

I ran the project as-is, went to the Login.aspx page and I am still getting "2015-07-02 07:53:29,267 [14] ERROR MonoX [::1] - Error
System.NullReferenceException: Object reference not set to an instance of an object.". 

Were you able to run your example successfully when you created it?

Shawn

9
7/2/2015 3:37:00 PM
3016 Reputation 428 Total posts

Hi,

just to check, did you build your solution?

Yes, I tested it in my environment, it works fine.

Regards.

10
1 2
This is a demo site for MonoX. Please visit Mono Software for more info.