you should simulate asp.net routing with cookie and user controls.
so we have just one aspx file named default.aspx and other pages should place into user controls.
put this script at the end of default.aspx :
<script src="https://code.jquery.com/jquery-2.2.0.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
$("a").click(function (e) {
e.preventDefault();
var attrHref = $(this).attr("href");
$.getJSON("/service.asmx/SetRouteCookie", { href: attrHref }, function (e) {
window.location.reload();
});
});
});
</script>
this script disable all links behavior then we handle click event manually.
in click event we call a web service method by ajax. this service set a certain cookie to hold current page:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, XmlSerializeString = false, UseHttpGet = true)]
public void SetRouteCookie()
{
if (HttpContext.Current.Request.QueryString["href"] != null)
{
string href = HttpContext.Current.Request.QueryString["href"];
HttpCookie c = new HttpCookie("CurrentRoute", href);
c.Expires = DateTime.Now.AddHours(1);
HttpContext.Current.Response.Cookies.Add(c);
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.Write("{\"status\":\"ok\"}");
}
}
after creating cookie and successful callback we reload page by javascript.
on default Page_Load event we load appropriate user control:
protected void Page_Load(object sender, EventArgs e)
{
#region process route
if (HttpContext.Current.Request.Cookies["CurrentRoute"] != null)
{
var route = HttpContext.Current.Request.Cookies["CurrentRoute"].Value.ToString();
string pageName = GetPageName(route);
Placeholder1.Controls.Add(LoadControl("/ctrls/" + pageName + ".ascx"));
}
else
{
Placeholder1.Controls.Add(LoadControl("/ctrls/default.ascx"));
}
#endregion
}
public string GetPageName(string href)
{
int index = href.IndexOf("&");
if (index == -1)
return href.Trim('/');
else
{
return href.Substring(0, index).Trim('/');
}
}
I created sample code on git:
HideRoute