Thursday, March 6, 2008

Reset Idendity Column

DBCC CHECKIDENT (tableName, RESEED, 0)

this resets the seed of all the idendity columns in the table

Saturday, March 1, 2008

Asp .Net - Role and Forms Authentication

A while Ago i decided to use both the Forms and role based Authentication for ASP .Net.

I had always created my own login, and used to create a session with the user information. Each time I loade a page that required access, my master pge woud have some code to check if a certain session existed, if not boot the user to the login page.

However Form Based Authentication meant that I would not have to remeber to create that code in every master page, especially when it was already there to use it.
Along with that, I wanted to use a role based authorization. Now with both these, while creting them using the Asp .Net configuration tool, always created its own database, and its own way of handling roles, and I felt i was not in control. Especially if i was to build a site admin to do that.

So I managed to search out articles on using my custom login control to my custom database, but the tricky part was assigning roles. I barely scratched the surface tring to search articles which would explain that.

With spending time trying to find out how it works, I struck upon the RoleProvider Class.
Within no time then i was able to create my custom roles, and now I could use my login table to hold the roles the user has, and make changes accordingly.

If you are struggling with the same I would be glad to help, until I put myself together and write up an article on it.

User Group and access manager

I was faced with the issue to create a user management in one of my applications, which allowed the user to only gain access to certain features of the Application.

Inititally, all the business required was to set up a user level, and then according to that level they would want the program to be hardcoded to allow access to users with atleast that access level..

Sounded a bit abnormal as the number of users was not small..it was medium and potential to grow, especially when the application had a possibility to be setup for other similar organizations.

So I then created this user group management, when you could create groups, and assign which features or programs the group had access to. Users could then be alloted to those groups. However certain users might be required to have access to some indiviadul features only, so that was also covered. I created this and applied it to a Windows forms, using 3rd party controls (Devexpress) and with its ribbon tabs, i could only show those tabs and those feature buttons to which the user had access to.

I had already started this from home, and created the management console in pure windows forms. Not as nifty as the 3rd party controls, but then serves the purpose in a similar way.
I created it as a DLL with its own database, however I was challenged with creating the strongly typed database to have access only to the database defined in the application refrencing this library.

The only catch to it is that the User's ID has to be in an integer format. Looking at this tool, It can be integrated into the management features, and can be used straigt from the box (just need to setup the database).

I have uploaded this to Codeplex and can be found at:
http://www.codeplex.com/AlterGearUserGrpMgmt

And yes I have a Name : AlterGear

This is filed under the LGPL Licence, so feel free to change anything in it and crete your own library from it.

At the moment, most of the code is within the form classes, So my next level to this is to split assignments into pure cs files so that the library can be used to build your own UI, rather than relying on the one provided within it. (Its not that bad)