views:

149

answers:

3

I'm posting data to a page called process.aspx that handles some business logic with the following code:

<%@ Page Language="C#" %>
<%
    MyData.process(Request);
    Response.Redirect("")
%>

this page I will be calling from a variety of pages. Is there some way of knowing from which page my form was submitted? I was thinking something along the lines of writing:

 <form id="frmSystem" method="post" action="process.aspx?page=<%=  %>">

However I don't know what to write in between the <%= %> to get the current page name. Can anyone help please?

A: 

You could pass in it in via a property like the ReturnUrl similar how a sign in page works. This is kind of how you are doing it up there.

You could also try to use the HttpContext.Current.Request.UrlReferrer to see who referred you.

Kelsey
HttpContext.Current.Request.UrlReferrer is working just dandy, I merely need to use only the page name + the query string now.
William Calleja
A: 

You can use Request.UrlReferrer.OriginalString to get the URI of the referring page.

Jeff Hornby
This seems to be the way to go, is there a way to get only the page and query string out of this method? I'm trying it and its working just dandy, all I need is to take only the page name + the query string.
William Calleja
If you want the entire path with out the http: part, you can use Request.UrlReferrer.PathAndQuery. If you actually want ONLY the page anme and query string, use System.IO.Path(Request.UrlReferrer.LocalPath) + Request.UrlReferrer.Query
Jeff Hornby
+1  A: 

You can capture the calling page URL and hold it in Session or ViewState for later use.

For example, in Page_Load,

Session["PreviousPage"] = Request.Url.ToString();

And then in your final event (perhaps Savebutton_Click or CloseButton_Click), you can do a redirect in either of these ways:

Server.Transfer(Session["PreviousPage"].ToString(), false);

or

Response.Redirect(Session["PreviousPage"].ToString(), false);

You can also get the URL of the calling page this way:

Request.ServerVariables("HTTP_REFERER")
DOK
You're welcome. I think it's a nice feature for a website to send the user back from whence they came.
DOK
Be aware that Request.Url.PathAndQuery can be faked. The way to store the previous page in the session seems to fit best in this situation.
citronas
This one did it, I found the 'Request.UrlReferrer.PathAndQuery' command! Thanks mate!
William Calleja