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)
Related
Ok, I've been bugging with this for too long.
I need to call my website from a rough VB.net app. Then only thing I need is to attach a query string parameter to the calling url, so I can distinguish the pages to be shown to different VB app users.
So I want to click a button and launch that website, giving this parameter.
First I was bugging with adding the system.web libraries. Now I can't use Request/Response.QueryString as well.
I tried getting some example help from this post. but as I said before - I cannot make use of Request.QueryString as I cannot import it.
I am stuck here:
Process.Start("http://localhost:56093/WebSite1?id=")
I need to attach a query string parameter to the url and then open the website with that url.
Can someone just give me a sample code for my problem.
Query parameters are parsed by the web server/http handler off the URL you use to call the page. They consist of key and value pairs that come at the end of the URL. Your code is nearly there. Say you needed to pass through the parameters:
ID = 1234
Page = 2
Display = Portrait
Then you'd turn them into a URL like this:
http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait
Therefore in your code you'd have:
Process.Start("http://localhost:56093/WebSite1?ID=1234&Page=2&Display=Portrait");
I need to check where did the incoming request came from before loading a page
ex:
for user to view www.mysite/page1.aspx
request should come through www.othersite/page1.aspx
so on page1 load in mysite i need to check whether the request came from page1 in othersite.
i have tried Page.Request.UrlReferrer but i saw there some posts which tells every browser might not support Page.Request.UrlReferrer.
i can not pass visible parameters on URL.
This is a common issue when you do not want to allow request from arbitrary sites.
What you can do is, create a variable in session and put this variable in the Page1.aspx. When the page posts back, you should get that variable back and it should also match the one stored in the session. If it does not, you can be sure that the request is from some other server.
You can use PostBackUrl on the start page
And access your parameters with PreviousPage in the arrived page
if (this.PreviousPage != null)
{
var control = Page.PreviousPage.FindControl("..."); //Adjust your Id and add cast
}
Nota : This was also created to provide greater security redirection setting.
Can anybody tell me how to pass a value from one web form to another web form without using a query string and session?
You can pass the Values over different pages via QueryString like:
Response.Redirect("yourNextpage.aspx?identifier=DesiredValue");
On your next page you can retrieve the value like this:
Request.QueryString["identifier"];
Other Preferred way would be Server.Transer() and Postbackurl.
Refer this link for various possible ways.
there are several ways you can pass parameters between pages.
Using a Query String
Getting Post Information from the Source Page
Using Session State
Getting Public Property Values from the Source Page
Getting Control Information from the Source Page in the Same Application
for more detail visit followng link.
http://msdn.microsoft.com/en-us/library/6c3yckfw.aspx
You could use a Querystring in this case:
Page.Response.Redirect("show.aspx?id=1");
And then read it on the other end:
int id = Page.Request.QueryString["id"];
Using PostBackURL, ex:
PostBackUrl="~/result.aspx"
and on result.cs (Page Load)
lblEmployeeNumber.Text = HttpContext.Current.Request.Form["txtEmployeeNumber"];
With Session:
For example you login the system and your id is 123123123.
string userid = 123123123;
Session["userid"] = userid;
When you go another page/pages your session is alive when your session timeout.
<system.web>
<sessionState timeout="1250"/>
</system.web>
It seems what you're looking for is something like the flash-, view- or conversation scope in Java EE and Ruby on Rails.
For ASP.NET you could perhaps take a look at this one: Is there an equivalent of JSF #ViewScope in ASP MVC?
depends on type and how much information you wish to transfer. for instance, if you want to transfer some variable (strings or integer values) you consider to use querystring (you can found here major information). for instance, if you want to transfer typed objects (class instance) you consider to use session (you can found here major information).
I have an aspx page, which is a "User Log-In" area. I want to pass the userid to another page which is linked from the aspx page.
the link I have looks something like this:
www.abcdefg.com/Home/Redirect/?authtkn=123456abcd=xxxx
I need the xxxx to be a session variable which in this case is userid.
**userid is not sensative information, this is simply to redirect the user to another page for specified information.
Any thoughts on how to pass a session variable to a URL, or if this can be done. The example www.abcdefg.com is a different domain (on a different server) from the original aspx page.
Why not appending like this?
string.Format("www.abcdefg.com/Home/Redirect/?authtkn=123456abcd={0}",
Session["UserId"]);
if i understood you correctly.
Think your question is how to maintain cross domain session or authentication.
Check this link Maintaining Session State Across Domains, may give you some idea
Or this one How can I share a session across multiple subdomains?
You don’t need to pass a session variable via the url. You can just start session on the next page and have access to all your session variables! If you do want the variables up there so you can quickly get to different userids with just a quick url change, send userid to the url on your previous page with with $_GET[ ].
i want to make some questions about asp.net mvc.Actually,i am not familiar with web developing.my questions are i have two controllers,one is login and another one is
profile.After login,i want to call profile.so,i use this way,
return RedirectToAction("DiaplayProfile","Profile",new { personID = Person.personID});
my problem is parameter that i passed are shown i URL.i don't want to show.In web developing,if we use post method to send data,parameters are not shown in url,is it correct?for me,i need to pass parameter ,but,i don't want to show at url.
How i use in post method in MVC RedirectToAction?i also tested with TempData
to pass data,but,it's gone after if i make refresh.how i hanlde this?And also,
can i use [AcceptVerbs(HttpVerbs.Post)] for solve this problem?
guide me right ways, please.
Regards
Chong
You can't do a post as part of a redirect; a redirect must be a get request since you're simply passing the browser the URL to which to redirect. In MVC, having the id as part of the URL is actually considered to be a good thing. I would embrace it. Rather than having the parameter be personID, I would use id so that the default routing can be used. Eventually I'd want to end up with a URL that looks like:
http://example.com/profile/display/1345
where 1345 is the id of the person in question. If you use default routing, that would mean that you have a ProfileController with a Display method that takes a single id parameter (of type int). You would redirect to it using:
return RedirectToAction( "display", "profile", new { id = 1345 } );
BTW, you can't use the AcceptVerbs attribute to control how a redirect is made, only to control what HTTP verbs the action will respond to. In this case, I think you really do want to accept a GET and I think you really do want to have the id in the URL.