根据我的理解,你希望这样做:
<><>>>>>
<a href="..../home.aspx?egSession=1">Take Me home</a>
Home.aspx.cs: The Code after page, in such as the OnPageLoad Activities
Session["egSession"] = Request.QueryString["egSession"];
Home.aspx
<div>Session: <% =Session["egSession"] %></div>
<div>Query String: <% = Request.QueryString["egSession"] %></div>
如果你在其中试图做到这一切,我将尝试如下:
APage.aspx.cs
建立公共方法(必要时改变投入参数的类型)
public string SessionMagic(object input)
{
Session["egSession"] = input;
return Session["egSession"].ToString();
}
APage.aspx
<a href="..../home.aspx?egSession=<%= SessionMagic(1)%>">A Link</a>
* 。 UPDATE: *
If you can not update the .cs files you can add server side code in the aspx page, not great practice but it can be done. Encapsulate the code in script tags with the run a server attribute set. E.g.:
<script runat="server">
public string ServerSideFunction(string input)
{
Session["egSession"] = Request.QueryString["egSession"];
public string SessionMagic(object input)
{
Session["egSession"] = input;
return Session["egSession"].ToString();
}
}
</script>