简体   繁体   English

ASP.NET在单独的虚拟路径中传递值

[英]ASP.NET Passing Values in Separate Virtual Path

I know how to pass values between asp.net pages if its on the same virtual but what about of i have sites on different virtual? 我知道如何在asp.net页面之间传递值,如果它在同一个虚拟站点上,但是我在不同的虚拟站点上又如何呢? would it be possible? 这有没有可能?

say i have this site1 说我有这个网站1

localhost/search/search.aspx 本地主机/搜索/search.aspx

then i have this site2 which processes the result from site1 然后我有这个site2处理site1的结果

localhost/result/result.aspx --> notice this is on different virtual to site1 localhost / result / result.aspx->注意,这是与site1不同的虚拟

now how would i pass the results from search site to result site. 现在我如何将结果从搜索站点传递到结果站点。

would that be possible? 那有可能吗?

The ASP.NET Button Web Control has a PostBackUrl. ASP.NET按钮Web控件具有PostBackUrl。 You can use this to to cause the post in search.aspx to be sent to result.aspx. 您可以使用它来将search.aspx中的帖子发送到result.aspx。

是的,您可以通过设置搜索按钮的PostBackUrl属性,将其回发到虚拟应用程序中的页面,然后通过Page.PreviousPage从页面发送访问控制值。

1) Querystring approach. 1)Querystring方法。 Construct a link like so :- 像这样构造一个链接:

/result/result.aspx?q=my+search+term

Pick it up in your code-behind with ( C# ) :- 用(C#)在您的代码后面拾取它:

Request.QueryString["q"] 

2) Or POST the variables via a form. 2)或通过表单过帐变量。

In your search page :- 在您的搜索页面中:-

<form action="/result/result.aspx" method="post">
  <input name="searchTerm" id="searchTerm" type="text" />
  <input name="go" type="submit" />
</form>

Note the lack of a runat="server" tag on the form. 请注意,表单上缺少runat="server"标记。

Pick it up on the code-behind of your results page as :- 在结果页代码的以下代码中将其提取为:-

Request.Form["searchTerm"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM