Passing a variable in ASP using reponse redirect - asp-classic

I'm trying to pass a variable using Response.Redirect I have a page that I'm processing the info on which contains:
divrec = request.QueryString("div")
divstring = "divisions.asp?"&divrec
Response.Redirect divstring
But when I try to retrieve the information in another page by using
<% divrec = request.QueryString("div")
%>
<% =divrec %>
The variable/string does not display

i think you missed the querystring parameter in your divstring variable.
Try this:
divstring = "divisions.asp?div="&divrec
You should be able to access the parameter in the receiving page now.

What you could do is get the parameter from the url.
So if you redirected the user to www.mysite.com/divisions.asp?something
You could parse it up to the ? and get everything after it.
Try looking at http://www.powerasp.net/content/new/get-current-page-url.asp
Also this page might help you out
how to pass values from one page to other?

Related

What is this redirection called and how can it be setup for an ASP based site?

Does this redirection method have a specific name, and how do I set it up for an ASP based site?
http://www.example.com/?URL=www.redirecteddomain.com
Ok, in that case, it not really the web server, but simply your code that can do this.
so, if you web page was:
http://localhost/MyJumpPage.aspx?URL=www.google.com
So, in your code, all you have to do is grab that 1st parameter, and then run code to jump/navigate to that page.
EG:
string strURL = "";
strURL = Request.QueryString("URL");
Response.Redirect("http://" + strURL);
So, the code behind a button, or even on page load can simply pull the query value from the url string, and then jump to that URL.

Pass parameter from 1 page to another using post method

I have a page "Demo.aspx". I need to set some parameters using post method and redirect the page to "DemoTest.aspx".
Is there any way to set parameters in post method in asp.net? I don't want to set "Querystring" due to security propose.
Also I need server side code for this. I am not able to use "Javascript" or "Jquery" for the same.
Here is some more description for the same.
Right now I am using Response.Redirect("www.ABC.Com/DemoTest.aspx?P1=2"). So the page is simply redirect to the given URL.
Now I don't want to pass that "P1" in "Querystring". Instead of query string I want to use Post method.
Please note that redirection page is not in my own application. So I cant maintain session or "Viewstate".
Thanks in advance.
Use a session variable and response.redirect to the next page.
Session["MyVariable"] = "someThing";
Response.Redirect("DemoTest.aspx");
The value stored in Session variables will be accessible across application.
you can store in session like this :
Session["id"] = "anyID";
To get values On another page you need to write
string id = Convert.ToString(Session["Id"]);
However
By default, in .NET pages post() do the things automatically.
You will need to do sumthing like this:
Server.Transfer("DemoTest.aspx", True)

ASP.net link to other page with passing parameter

my question is, how to call another aspx page from same project, with passing parameter, like ID-20?
Thanks.
In the source page, you can pass data with query string
.../target.aspx?Id=20
Then on target page get those values
String s = Request.QueryString["Id"];
Notice that you shouldn't pass any sensitive data by this method
Response.Redirect( "another.aspx?id=20" );

asp Server.Transfer put parameter

i googled many samples, all show such code
Server.Transfer("/default.asp?p=news")
but i get error -An invalid character was specified in the Path parameter for the MapPath method.
can you help me?
Server.Transfer method actually doesn't support any kind of querystring specified in the path. You can try to store the query parameter in a session value instead.
Some discussions:
http://classicasp.aspfaq.com/general/why-won-t-querystring-values-work-with-server-execute/server-transfer.html
The following might be a work around to using server.transfer or response.redirect.
Response.Write "<script language=javascript>window.location.href = '/default.asp?p=news';</script>"
You would have to include your querystring on the page that does the server transfer.
Ie:
page.asp?p=news would include:
Server.Transfer("default.asp")
default.asp would include:
sParam = Request("p") '<-- Your querystring value from page.asp
This should work, or if your app isn't flexible to do this, you can use Session to pass the value. It says here which methods are allowed for passing variables using Server.Transfer: http://msdn.microsoft.com/en-us/library/ms525800%28v=vs.90%29.aspx

Asp.Net System.Web.Routing Find actual .aspx Page

I'm using System.Web.Routing to have some better URL's and have come across a problem. I need to know the actual page that's handling the request.
for example a request comes in as:
/basketball/home
I need to find the page that handles that request, like:
/management/default.aspx
I'm only using the System.Web.Routing and not MVC. I have a handle to the RequestContext that contains some of the route information, but i don't see what i need.
Thanks in advance.
******* UPDATE *******
I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.
There is actually another simple way to get the actual page:
String vPath = ((System.Web.Routing.PageRouteHandler)Page.RouteData.RouteHandler).VirtualPath
Do not forget to check Page.RouteData.RouteHandler is not null - while you are getting the page w/o ASP.Net routing but directly.
Can you not retrieve this from the current HttpContext object?
Perhaps something like this:
public string GetCurrentPageName()
{
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}
UPDATE:
Have you tried this article?
How to: Construct a URL from a Route
You should be able to retrieve it back from the Routing table you have constructed.
vhinn terrible's answer worked...
Page.AppRelativeVirtualPath
You just have to remove the initial tilde ("~"), and you're ready to go.
var path = Page.AppRelativeVirtualPath.Replace("~", String.Empty);
I don't know why it was downvoted. Worked for me like a charm.
Try using this code:
Page.AppRelativeVirtualPath
I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.

Resources