Skipper Geffen
Skipper Geffen

Reputation: 75

More code or more web pages?


I'm building a simple ASP.NET application that consists of four pages: Sign Up, Log In, Customer Page, Admin Page.
Upon logging in to the system there is a code about 30 lines long that sets some session parameters and does other important stuff.
Note: I can't run this code in the Log In page

So, What I'm ending up with is this bulk of code duplicated at Customer Page and Admin Page. One Solution I was thinking about is creating a fifth page called LoggingGateWay. After successful logging in the LogIn page, users will be redirected to this page. It will run the bulk of code, and then redirect the users to one of the secured pages. The question is whether loading another page and having more transportation in this case is better than the duplication of code or not?
Thanks ahead for the answers! :)

Upvotes: 0

Views: 32

Answers (1)

BLSully
BLSully

Reputation: 5929

If this is code that has to run on each of the "internal" pages of your application, and you're using Webforms rather than MVC, create a master page with the required code, and then utilize that master page for each of your internal pages.

The other option is to create a base Page for all your internal pages to use, that inherits from System.Web.UI.Page and make your internal pages inherit from your custom Page rather than the default.

Upvotes: 3

Related Questions