You can create a new class that inherits from System.Web.UI.Page , and add this piece of logic here, and then use the new class for all of your pages.
EDIT:
something like that
public class MyPage : System.Web.UI.Page { public MyPage() { Load += MyPage_Load; } void MyPage_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Page.Request.UrlReferrer == null) { Response.Redirect("test.aspx"); } } } }
and add this to web.config
<system.web> <pages pageBaseType="MyNamespace.MyPage" /> </system.web>
source share