Reuse control

D

DKode

Hello,

I have created a set of classes and controls that I re-use on almost
every project I use for my company.

It performs the following things:

It has 3 web controls for (loginControl, loggedOut, loggedIn)
loginControl is added to a page and then the appropriate loggedOut or
loggedIn is displayed to perform logging in.
I also have about 40 lines of code that is placed into Global.cs under
the Application_AuthenticateRequest that creates the authentication
cookie.

In my BusinessLayer I have a class called ADAuthentice.cs which
performs authentication against AD/LDAP and checks their credentials
they supply in the loggedOut control.

Now, How do I package these controls/class into a nice little library
that I can re-use without changing a ton of code each time I re-use it
in a new project. As it is right now, I have to add in all the seperate
files to use each time which is kind of a pain. Is there an easier way
to package all of this stuff up and then just re-use it easily or am I
already at the point that it is as packaged as possible?

Thank you for your help

DKode
 
K

Karl Seguin

DKode:
Your 40 lines of code which you place in each Global.cs file can be placed
inside a class which implements IHttpModule and then you can register that
class via the web.config... More on that here:
http://msdn.microsoft.com/library/d...en-us/cpguide/html/cpconcustomhttpmodules.asp


Your 3 webcontrols would need to change to server controls (I take it they
are user controls).

This would make your entire class into a single .dll which you could
reference in any project, add the custom HttpModule to the web.config and
<%@Register the loginControl on pages which need it.

Karl


--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
S

Scott Allen

Hi DKode:

Have you tried the project type of 'class library'? This will produce
an assembly that you can reuse from other projects.

Inside the library you can add the ADAuthenticate.cs file - this would
be an easy copy and paste.

Rip out the code you have in Global.asax.cs and place it inside a
class deriving from IHttpModule. You can plug an HttpModule class into
an application with a simple change in the app's web.config file, and
an HttpModule sees the same events that you catch in Global.asax.
There is some more info here:
http://msdn.microsoft.com/library/d...en-us/cpguide/html/cpconcustomhttpmodules.asp

The hardest part would probably be packaging the three controls into
the library. If these are user controls there is unfortunately no easy
way to package them, but if you convert them into server controls you
can have them completely contained in the library. Samples here:
http://msdn.microsoft.com/library/d...s/cpguide/html/cpconservercontrolssamples.asp

HTH,
 
D

DKode

Ok,

I have created most of the code in the custom DLL. The only problem I
am having now is with generating the actual HTML controls that will
appear on the webpage, such as userName (TextBox), passWord(TextBox),
lblError (Label for error messages)

I reference these controls in my code by name to perform processing,
now if I dynamically generate these controls on my page, how to I
reference them from code? I'm a little confused when it comes to
generating the HTML that will appear on the form.

Can anyone point me in the right directions concerning dynamically
generating/rendering the html controls?

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,279
Latest member
LaRoseDermaBottle

Latest Threads

Top