Passing a variable from page to page using ASP.NET (C #) without using QueryString

Look for advice on passing variables from page to page without using QueryString. Web crawlers such as google fall into search queries found in the URL. I am trying to get away from using it. Is there any other suggested method for passing variables? I thought about using session variables, but it's just for simple passing a variable from page to page, and they will not always be the same. Any ideas?

On the other hand, I cannot do this using forms. I am using a homepage with a form embedded in the homepage, as well as content pages. If microsoft has not updated it so you can use multiple forms on the same page.

+3
source share
8 answers

You can look at ASP.NET Routing (which can be done without MVC) - then you can have a data path, but without a query string; as are the paths (which are actually MVC but the same logic applies).

Unable to use forms - you can just use jQuery or similarly to create forms on the fly.

+4
source

What about ASP.NET session storage?

You can store material in a session on your page and retrieve it from there on your second page.

, , , . - , , , .

:

+2

ASP.Net.

, :

  • ( ), (.. , );

  • POST (). -;

:

  • ASP.Net;

  • cookie.

, , , POST (). , , . Ruby on Rails - , , POST . , , http://google.com , POST, HTML:

<a href="http://google.com" onclick="
    var f = document.createElement('form');
    f.style.display = 'none';
    this.parentNode.appendChild(f);
    f.method = 'POST';
    f.action = this.href;
    var m = document.createElement('input');
    m.setAttribute('type', 'hidden');
    m.setAttribute('name', 'param1');
    m.setAttribute('value', 'value1');
    f.appendChild(m);
    f.submit();
    return false;">Google.com using POST</a>

, , HTML . document.createElement('input'); appendChild , , .

+1

, Cookie. , cookie.

0

, HTTP. - , /

0

, , , , - /:

 Application.Lock();
 Entity e = new Entity("mine");
 Application["myVar"] = e;
 Application.UnLock();
0

:

  • Session
  • Cookies
  • ViewState ( , )
0
source

On the main page there is a text box and a button like ...

<asp:TextBox ID="input" runat="server"></asp:TextBox>
<asp:Button ID="Bt" runat="server" Text="Button" PostBackUrl="~/Getvalue.aspx" />

Now you can get the value TextBoxfrom the previous page toGetValue.aspx

  • On aspx page

<%=Request.Form["input"]%>

or

  • In the code file

TextBox1.Text = Request.Form["input"]; (TextBox1 is in  "GetValue.aspx" )
0
source

Source: https://habr.com/ru/post/1773185/


All Articles