There is no problem with your code just a small modification makes your program works correctly.
As mentioned above
protected void Page_Load(object sender, EventArgs e)
{
if(Session["UserName"] != null)
lblUser.Text = Session["UserName"].ToString();
else
Response.Redirect("SessionTimeoutMessagePage.aspx");
}
you have to change your code like this. Because when ever you clicked on some link on some aspx page in your website which associated with the masterpage it throws you an error.
Because every time the control loads your master page first and when executing the page_load event you are blindly looking for some session value.
Remember the ASP.NET doesn't show a null/empty value if the session was not created. It throws you an error for that reason.
So you have to check whether is there any session created or not before assigning the session value to any label to display eg: welcome XXXX
So kindly refer the above code now you can understand clearly why you are getting the error and not to get in your future.
I hope this will be useful to you. If it helps you kindly give 5 star rating and make it solved.
Thank you