How to create a class library for asp.net

I am new to ASP.NET. I have a general idea with ASP.NET on how to create a web application? But here I ask a question because I want to apply the best practice for my coding. So, I want to separate the conceptual layers, for example, I want to create a function that checks the session on page_load if it is empty, than redirecting to the default page. I can do this by copy-pasting onto each new page. But I would like to call a function and not do Copy / Paste.

I am going to create a library for accessing data, as well as connect and perform data manipulations. Is it possible?

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

Can i use this concept?

+4
source share
5 answers

Right. For the data access level, you can create a ClassLibrary project and add a compiled dll as a reference to your WebApplication project.

Below is the MSDN Link link with instructions on how to do this.

Note: But ideally, you could have another ClassLibrary Project for Business Logic Layer, where you can reference the Data Access Layer dll; and then you can add the Business Logic Layer dll to your web application (it’s all about creating a loosely coupled architecture and building scalable software, again it will depend on the needs of the business)

To begin with, it's good to read the Microsoft Application Architecture Guide

+3
source

That's right. Just create a new class library project in Visual Studio and specify it in your ASP.Net project.

+1
source

Read about

Base page

Inherit all of your pages from this base page. this will help you have an OOP approach and also save you problems

Copy paste

+1
source

Add a class library to your solution as shown below. And then you can move your data access and data processing code to classes in the class library.

Add a link to this class library project in your web application. Now you can call the functions that you defined in your classes in the class library in your web project.

VS 2010 Adding a class library.

VS 2010 Adding Class Library

+1
source

Create a base class, say, "MyAppPage" and override the OnInit event. In the on-init event, verify the session. If null, then redirecting to your login page is still ongoing. Extract all your pages from the base class instead of System.Web.UI.Page. It will be nice if you follow this also for custom controls. It is always useful to have a base class.

-1
source

Source: https://habr.com/ru/post/1415043/


All Articles