Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jan 10, 2013 10:04 PM by otnielpena
Jan 08, 2013 10:27 PM|LINK
I have an ASP.NET Web Forms application.
In this application I have a Login.aspx page with code behind. Now I would like to create
LoginLight.aspx lightweight version of Login.aspx page. The light version should have less HTML content and should use the key functions of
Login.aspx.vb code behind. These functions have a lot of code.
Therefore, in order not to have a lot of duplicate code, I would like to move the common functions to a common file. I was thinking about placing those functions in a class library in the
App_Code folder but I read on the web that is not a good solution.
I also read that to have the same code behind file for two different pages is not a good practice. How would I tackle this issue?
Jan 08, 2013 11:39 PM|LINK
" I read on the web that is not a good solution"
Jan 08, 2013 11:45 PM|LINK
Whether it is a good programming practice or not, I would let yourself judge it and research it, however, if you make that one page inherits from the otherone, you would have only one code behind file for both pages. All the code and Event Handlers would
be placed in only one page, so you would need only to place the mark up in one page but writing the code in the other one (which would handle both). The Event Handlers in the inheriting page would have a green sign by intelisense stating a required overloading
of the base class file (the page from it is inheriting).
Jan 09, 2013 04:26 AM|LINK
not it is not true- u can put the shared code in App_code there is no issue at all
Jan 09, 2013 04:43 AM|LINK
best practice is to make layered arcitechture. you can make a business logic layer for your appication. and you can create a class for userlogin. that will be accessable by all the application layer classes which you use the business layer's namespace. this
is really a gud practice to create a centralize logic.
Jan 09, 2013 09:57 AM|LINK
I read that if you place too much code in the App_code the performances of my application decrease. Morevoer the App_code folder is meant to contain utilities functions rather than business logic
Jan 09, 2013 10:10 AM|LINK
I already use the three tier architecture. The problem in my case is that I am maintaining an already existing Web application which is coded in VB.NET. I create a two class libraries projects, one for the
Service Layer and one for the Repository Layer, coded in C#.
The code for authentication in Login.aspx has been developed around 2000 and you might guess how obsolete and "spaghetti" is. Building a Service and Repository components for logging in, requires a really deep analysis of the existing code
in Login.aspx in order to translate the code in C#, get rid of obsolete objects and functions and create methods in the Service Layer. I plan to do it in the future but at the moment it is out of project's scope
Jan 09, 2013 10:13 AM|LINK
In my projects I have always used just Master pages. My notion of page inheritance of Web Pages is limited to this topic...can you point towards good articles where this topic is explained? However one of the reason I want to create a LoginLight.aspx page
is because Login.aspx uses a Master page and I do not want LoginLight to use it. I guess if I inherit the from Login.aspx page I also inherti from the Master page...
Jan 09, 2013 10:24 AM|LINK
There is no issue to write code in App_code folder othere wise you can create common class in businesslogic and implement.
Jan 10, 2013 10:04 PM|LINK
Thinking more about the issue:
You can create a custom Usercontrol to login and load it in each page as needed also. That way you can load the control no matter which page is. That way you do not have to repeat code in each page, but only in the custom Usercontrol with the common functionality
you whish to use.