Search code examples
c#n2n2cms

N2 Customize Login Logic


We have a need to customize the logic of our N2 authentication to add a couple of options.

I need to add a RadioButtonList that contains some options and set a session var based on the selection of that RadioButton on Login - otherwise the user cannot see the site in the preview pane of N2. I thought I could just add the RadioButtonList to the N2/Login.aspx and create a custom Login Class that extended N2.Edit.Login and override the Login1_Authenticate method to do my custom logic before calling base.Login1_Authenticate. It seems that it is not designed to be extensible and I cannot override that method. To make my change I would have to do a custom compile of N2 with these changes, which I want to avoid (should be closed to modification but open to extension) so we don't have to redo our changes every time we update N2.

Another route I tried was to create N2/CustomLogin.aspx and add all of my logic in that custom class and set the web.config to point to CustomLogin.aspx instead of Login.aspx - this sent me to the correct login page initially but a failed login redirected me to Login.aspx (assuming something hard coded) which did not have our radio button options.

We are using N2 CMS 2.0.0.0 on .Net 4.0 (MVC app)


Solution

  • N2 uses standard Forms Auth, ASP.NET Membership and Roles providers under the covers. As long as the logged on user is either named admin or is in one of the 3 N2 standard roles (Administrators, Editor and Authors - I think), you will be able to access the admin site.

    So I recommend you create a completely separate login page in your app. Point forms auth at your custom login page using an entry like this in your web.config:

    <authentication mode="Forms">
      <forms loginUrl="~/account/login"
             timeout="2880" />
    </authentication>
    

    In your custom login form you can do the standard forms auth stuff to get the user signed in, as well as setting your session variable.

    I've done this a few times and it works fine. If you can't get it working I suggest you provide a sample that demonstrates the problem and I'll see if I can help.