Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create class library for asp.net

Tags:

c#

I am new to ASP.NET. I have a general idea with ASP.NET on how to create a web application? But Here, I am asking the question because I want to apply best practice for my coding. So, I want to separate conceptual layers, for example, I want to create function which check session on page_load, if its empty than redirect to default page. I can do this by copy-paste to each new page.but I would like to call function rather than doing Copy/Paste.

I am thinking of creating library for Data Access as well as to connect and do data manipulations. Is it possible?

I just found this article from googling : Application Archi...

Can I use this concept?

like image 312
Hakoo Desai Avatar asked May 30 '12 03:05

Hakoo Desai


4 Answers

Correct. For the Data Access Layer, you can create a ClassLibrary Project and add the compiled dll as a reference to your WebApplication project.

Here is a MSDN Link with the steps on how to do this.

NOTE: But ideally you can have another ClassLibrary Project for Business Logic Layer, where you can reference your Data Access Layer dll; and then you can add the Business Logic Layer dll to your Web Application (it's all about achieving loosely coupled architecture and building scalable software; again this will depend on business needs)

To start with, here is a good read on "Microsoft Application Architecture Guide"

like image 142
Prashanth Thurairatnam Avatar answered Nov 17 '22 13:11

Prashanth Thurairatnam


Absolutely. Just create a new Class Library project in Visual Studio and reference it in your ASP.Net project.

like image 22
Andrew Cooper Avatar answered Nov 17 '22 14:11

Andrew Cooper


Add Class Library to your solution as shown below. And then you can move your data access & data manipulation code in classes in the class library.

Add a reference of this class library project to your web application. Now you will be able to call the functions that you have defined in your classes in Class Library in your web project.

VS 2010 Adding Class Library ..

VS 2010 Adding Class Library

like image 1
Kapil Khandelwal Avatar answered Nov 17 '22 13:11

Kapil Khandelwal


Read about

Base Page

Inherit all your pages from this base page. this will help you in having a OOP approach and also save you the trouble of

Copy-Paste

like image 1
avani gadhai Avatar answered Nov 17 '22 13:11

avani gadhai