Hi,
//Global.asax
public class Global : System.Web.HttpApplication
{
public static int value = 0;
}
Suppose you have your links in Menu.aspx page.
<form id="form1" runat="server">
<div>
<asp:hyperlink id="hyp" runat="server" navigateurl="~/Check.aspx" text="Clickme" onclick="redirect(event,this)" xmlns:asp="#unknown"></asp:hyperlink>
<asp:hyperlink id="hyp1" runat="server" navigateurl="~/Check1.aspx" text="Clickme1" onclick="redirect(event,this)" xmlns:asp="#unknown"></asp:hyperlink>
<asp:hyperlink id="hyp2" runat="server" navigateurl="~/Check2.aspx" text="Clickme2" onclick="redirect(event,this)" xmlns:asp="#unknown"></asp:hyperlink>
</div>
<script type="text/javascript">
function redirect(e,a) {
e.preventDefault();
var url = a.href;
$.ajax({
type: "POST",
url: "Menu.aspx/SetValue",
data: "{ 'URL': '" + url + "' }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
window.location.assign(url);
},
failure: function (data) {
}
});
}
</script>
</form>
// now your code behind
[WebMethod]
public static void SetValue(string URL)
{
string path = new Uri(URL).AbsolutePath;
switch (path)
{
case "/Check.aspx":
Global.value = 1;
break;
case "/Check1.aspx":
Global.value = 2;
break;
case "/Check2.aspx":
Global.value = 3;
break;
}
}
// one of your redirect to page in this example suppose Check.aspx
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Global.value != 1)
{
Response.Redirect("Menu.aspx");
}
else
{
}
}
}
Hope it helps you.
Thanks.