use a if condition to find which page redirects to current page in asp.net
I am redirecting to sendmessage page from group page and user page. In the sendmessage server side code how can I find which page redirected to send message page. since I have different code for each page i need to开发者_运维问答 use a if condition to determine it. how to code the if condition.
From user page
<asp:ImageButton ID="SendButton" ImageUrl="Styles/Images/Message.jpg" Enabled="True" Width="" runat="server" PostBackUrl='<%# Eval("Email", "SendMessage.aspx?Email={0}") %>'></asp:ImageButton>
From Group page
<asp:ImageButton ID="SendButton" ImageUrl="Styles/Images/Message.jpg" Enabled="True" Width="" runat="server" PostBackUrl='<%# Eval("groupname", "SendMessage.aspx?=groupname={0}") %>'></asp:ImageButton>
I tried this but it didn't work
string url = Request.UrlReferrer.AbsoluteUri;
if (Request.UrlReferrer.AbsoluteUri.ToLower().Contains("SendMessage.aspx?GroupName"))
{}
[url= http://localhost:48996/SurelyK/SendMessage.aspx?GroupName=iCam]
Simples! HTTP provides a header which your browser may (or may not) fill in, all you need to do is check it on sendmessage page. It can be accessed via:
Request.UrlReferrer
Now do a simple test based on the expected pages.
There are also a number of other options such as adding variables to the GET request which can also be accessed on the next page, but the above should suffice.
You can get the URL of the previous page via Request.UrlReferrer
inside the sendmessage page
try and check like this:
if(Request.UrlReferrer.AbsolutePath=="/Group.aspx")
;//do something
else if(Request.UrlReferrer.AbsolutePath=="/Page.aspx")
;//do something else
You can do a check against the UrlReferrer like this:
if (Request.UrlReferrer.AbsoluteUri.ToLower().Contains("groups.aspx"))
{
//logic
}
精彩评论