1

how to avoid writing this page load code in all pages of application ? can we write this in global.asax file?

protected void Page_Load(object sender, EventArgs e)
{
  Session["prevUrl"] = Request.Url;
  string PreviousUrl = Session["prevUrl"].ToString();
} 
Izzy
  • 6,740
  • 7
  • 40
  • 84
krishna mohan
  • 437
  • 1
  • 4
  • 18
  • Have a look [here](http://stackoverflow.com/a/560115/3793448) it should give you a good understanding – Izzy Mar 23 '15 at 10:09

1 Answers1

1

No. Global.asax is only initializing when the application is starting. My suggestion is to create a base class for your pages to inherit from.

public class CommonPage: Page
{
    public CommonPage()
    {
        this.Load += Page_Load;
    }

    private void Page_Load
    {
        Session["prevUrl"] = Request.Url;
    }
}
fjeldseth
  • 121
  • 4