0


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! :)

4

1 回答 1

3

如果这是必须在应用程序的每个“内部”页面上运行的代码,并且您使用的是 Webforms 而不是 MVC,请创建一个包含所需代码的母版页,然后将该母版页用于您的每个内部页面页。

Page另一种选择是为所有要使用的内部页面创建一个基础,该基础System.Web.UI.Page继承自您的自定义页面,并使您的内部页面继承自您的自定义页面,Page而不是默认页面。

于 2012-10-05T12:23:45.067 回答