Reputation: 185
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?
Upvotes: 5
Views: 17885
Reputation: 4361
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"
Upvotes: 5
Reputation: 16144
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 ..
Upvotes: 1
Reputation: 460
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
Upvotes: 1
Reputation: 32576
Absolutely. Just create a new Class Library project in Visual Studio and reference it in your ASP.Net project.
Upvotes: 1
Reputation: 1563
Create a base class say 'MyAppPage' and override OnInit event. In the on init event check for the session. If null then redirect to your login page else continue. Make all your pages derived from your base class instead of System.Web.UI.Page. It will be good if you follow this for user controls also. Its always good to have your base class.
Upvotes: -1