PageCreatedEventHandlerPovider Not firing ?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
1/11/2010 9:46:15 PM
Gravatar
Total Posts 101

PageCreatedEventHandlerPovider Not firing ?

I've created a PageCreatedEventHandler Provider (as per the docs).

 

using System;
using System.Configuration.Provider;
using System.Collections.Generic;
using System.Text;
using mojoPortal.Business;
using mojoPortal.Business.WebHelpers;
using log4net;

namespace mojoPortal.Business.WebHelpers.PageEventHandlers
{
public class HVGSPageCreatedEventHandler : PageCreatedEventHandlerPovider
{
private static readonly ILog log = LogManager.GetLogger(typeof(DoNothingPageCreatedEventHandler));

public HVGSPageCreatedEventHandler()
{
}

public override void PageCreatedHandler(object sender, PageCreatedEventArgs e)
{
if (sender == null) return;

PageSettings page = sender as PageSettings;

// ------------------------------------------------------------------------
// TODO.
// ------------------------------------------------------------------------
// My Code Goes here...
// ------------------------------------------------------------------------

log.Info("HVGSPageCreatedEventHandler handled PageCreated event for " + page.PageName);
}
}
}

This compiles to an assembly called HVGSMojoAccess.dll

I then created a file called

HVGSMojoAccess.config which contains:

<?xml version="1.0" encoding="utf-8" ?>
<PageCreatedEventHandlers>
<providers>
<add name="HVGSPageCreatedEventHandler" type="mojoPortal.Business.WebHelpers.PageEventHandlers.HVGSPageCreatedEventHandler, HVGSMojoAccess" description="HVGS MojoPortal Access" />
</providers>
</PageCreatedEventHandlers>


Placed the DLL into the bin directory, placed the .config file into the Setup\ProviderConfig\pagecreatedeventhandlers\ directory.

Stopped and started the Webserver.

 

BUT nothing is appearing in the log ? I would have thought a message would have appeared like:

HVGSPageCreatedEventHandler handled PageCreated event for ......


Did I miss something ??

Thanks

Andrew


 

1/12/2010 5:02:55 AM
Gravatar
Total Posts 18439

Re: PageCreatedEventHandlerPovider Not firing ?

Hi Andrew,

Looks like you declared the wrong type of logger

private static readonly ILog log = LogManager.GetLogger(typeof(DoNothingPageCreatedEventHandler));

It should be:

private static readonly ILog log = LogManager.GetLogger(typeof(HVGSPageCreatedEventHandler ));

I also would recommend you use a custom namespace.

Just add this at the top:

using mojoPortal.Business.WebHelpers.PageEventHandlers;

and change the namespace containing your handler to whatever you want like:

namespace HVGS.Web
{ ...

Then you'll need to change it in your config file as well.

Hope it helps,

Joe

1/12/2010 5:31:01 AM
Gravatar
Total Posts 101

Re: PageCreatedEventHandlerPovider Not firing ?

Ahhh.. Yes.. My ooops....

Thanks for pointing it out..

Will make the changes as you said..

Thankyou very very much...

I'm using Mojo for an intranet/dashboard i'm developing for Hunter Valley Grammar School.

It uses XML/RSS/iFrame content, custom pages etc..

It will have 120 teachers getting their daily updates each day.

The school has a secure login system, and a rest server which can validate IP addresses to user accounts which refreshes every 5sec.

My plan is to have each page check if the IP address is a valid active users (via REST call). If they are.. Display the page.

If not.. Redirect the page to the secure network authentication system. (outside Mojoportal). Then once they are logged in they can access the dashboard.

Again.. Thanks for your help.

1/12/2010 5:42:47 AM
Gravatar
Total Posts 18439

Re: PageCreatedEventHandlerPovider Not firing ?

PageCreated event only happens when a new page is created in the site hierarchy. It does not fire for every request of a page.

You could do that ip checking in a custom HttpModule where you can respond to the BeginRequest event.

However no matter where you implement this I think it will have performance problems if every page request involves the server making a server side web request against another service and waiting for the web response from the other server before rendering the page. This will also be putting a load on the rest service. I mean probably it will stand up to it since there is only 120 users. 

Best,

Joe

1/12/2010 5:44:04 AM
Gravatar
Total Posts 18439

Re: PageCreatedEventHandlerPovider Not firing ?

Hey Andrew, Many Thanks for the beer!

Cheers,

Joe

1/12/2010 5:55:26 AM
Gravatar
Total Posts 101

Re: PageCreatedEventHandlerPovider Not firing ?

No problem..  Your always quick to reply, product is excellent, support is excellent. I hope I can send some more your way..

I gather a better way would be to do a custom login provider ?

Which does the lookup call from the sign-in page, then sets the authenticated status to true for a generic teacher account ?

If not authenticated redirect to the sign-in page ?

If so.. Whats the best/closest login provider to hack into a REST/IPAddress login provider ?

Again thanks for your support.

Andrew

 

 

1/12/2010 6:04:26 AM
Gravatar
Total Posts 18439

Re: PageCreatedEventHandlerPovider Not firing ?

If the validation is simply ip address based, like if the ip address is in the database it is valid and if not it is invalid. It would be more ideal if you could talk directly to the database rather than through a server side web request. Waiting on a response from the rest service will be blocking until it returns and will be a performance bottle neck whereas a direct lookup in the db would be very fast.  You could do this in a custom HttpModule or you could replace the login page with a custom one do whatever validation you like and if valid set the authentication cookie to sign the user in. I guess it depends how often you need to check if the ip is valid.

Hope it helps,

Joe

1/12/2010 6:17:59 AM
Gravatar
Total Posts 101

Re: PageCreatedEventHandlerPovider Not firing ?

Yes.. Simple IP lookup.

The secure client system stores the active users ip address in an sqlserver database table. (along with their machine name, login name, etc etc).

Its refreshed in the database every 5sec by from a service running on the teachers machines. When the machine is switched off the database

timerstamp becomes old and the users is considered invalid. If they log out and another teacher logs in, their details are in the database.

Its used by a number of inhouse systems to allow single login without the NTLM drama's. (a hack.. But good enough for a school..)

So..

Yes.. I could easily access the activeuser table from the httpmodule as you suggested. (removing the rest server delay).

The security doesn't need to be strong, no student data is in the dashboard, just timetable/teacher notices/calendar/assessment times/etc.

So a single validation via authenicated cookie would be ok also..




I'll try the HttpModule first, then switch to the authenicated cookie if the speed is to slow as per a previous thread.

http://www.mojoportal.com/Forums/Thread.aspx?pageid=5&mid=34&ItemID=7&thread=4106&postid=17158


Thanks.


 

1/13/2010 6:24:02 PM
Gravatar
Total Posts 101

Re: PageCreatedEventHandlerPovider Not firing ?

Thanks Joe for all your help..

IP/ActiveUser code is now working well.   My hack/prototype is shown below:

It redirects to a page containing the special site specific login.

===============================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.IO;
using System.Web;
using log4net;
using mojoPortal.Business;
using mojoPortal.Business.WebHelpers;
using mojoPortal.Web;

namespace HVGS.Web
{
public class HVGSActiveUserHttpModule : IHttpModule
{
private static readonly string loginPage = "/login.aspx";
private static readonly ILog log = LogManager.GetLogger(typeof(HVGSActiveUserHttpModule));
private static ActiveUsersDataContext db = new ActiveUsersDataContext();

public void Init(HttpApplication application)
{
application.BeginRequest += new EventHandler(BeginRequest);
}


private void BeginRequest(object sender, EventArgs e)
{
HttpApplication app = ((HttpApplication)sender);
HttpContext context = app.Context;
string ip = SiteUtils.GetIP4Address();

try
{
if (IsActiveUser(ip)) return;
}
catch (DbException ex)
{
log.Error("handled exception: ", ex);
}
catch (InvalidOperationException ex)
{
log.Error("handled exception: ", ex);
}

log.Info(string.Format("Attempting page redirect: {0} for {1}",loginPage,ip));
context.RewritePath(loginPage);
}


private bool IsActiveUser(string ip)
{
// Check the ActiveUser Database and return True or False
return db.ActiveUsers.Where(qry => qry.IpAddress.Equals(ip)).Count() > 0;
}


public void Dispose() { }

}
}

=================================================================

Also remember to modify the web.config file.

I placed the following just above the: <-- comment this out ... Medium trust --> line.

<add name="HVGSActiveUserHttpModule" type="HVGS.Web.HVGSActiveUserHttpModule, HVGSActiveUserHttpModule" />

 

You must sign in to post in the forums. This thread is closed to new posts.