Webmatrix——将变量从cshtml页面传递到aspx页面

时间:2021-10-31 10:11:29

I'm using Webmatrix to build my site which renders different fusioncharts when users click on different buttons, i.e. if they click on the "Europe" button, they get a graph of avg temperatures in Europe, if they click on US, US avg temperatures etc...

我正在使用Webmatrix建立我的网站,当用户点击不同的按钮时,会呈现不同的fusioncharts,也就是说,如果他们点击“欧洲”按钮,他们会得到欧洲avg温度的图表,如果他们点击“美国avg温度”等等……

The cshtml page holds the session variable UserId after succesful login and if that user clicks a button if(ispost) code refreshes the whole cshtml page which then contains an updated graph.

cshtml页面在成功登录后保存会话变量UserId,如果该用户单击一个按钮,如果(ispost)代码刷新了整个cshtml页面,那么该页面将包含一个更新的图表。

On refresh, within the cshtml page there is an iframe whose source is a file called "Using_MS_SQL_Server.aspx" which in turn creates an xml file populated by the execution of a stored procedure on the ms sql database like so:

在刷新时,在cshtml页面中有一个iframe,其源文件为“Using_MS_SQL_Server”。aspx"反过来创建一个由在ms sql数据库上执行存储过程填充的xml文件,如下所示:

SqlCommand query = new SqlCommand(
    "EXEC ON_WEBSITE_SQL_DB.dbo.AVG_TEMPS_PER_CONTINENT "
     + AREA + ", " + USERID, conn);   

As you can tell, there are two variables to plug into the stored proc: AREA and USERID...

正如您所看到的,有两个变量要插入到存储的proc中:AREA和USERID…

Within the aspx.cs page's code I can easily call the USERID variable as it is a session variable using MembershipUser user = Membership.GetUser();.

在aspx之内。我可以很容易地调用cs页面的代码,因为它是一个会话变量,使用MembershipUser = Membership.GetUser();

How do I pass a variable with the value "EUROPE" from the cshtml page that the user is clicking to the aspx page for use in the stored procedure that is waiting for the AREA variable?

如何从用户单击的cshtml页面中传递一个值为“EUROPE”的变量,以便在等待AREA变量的存储过程中使用?

1 个解决方案

#1


1  

The only ways you'd be able to achieve that is either using session/cookies or the query string.

您能够实现这一点的唯一方法是使用会话/cookie或查询字符串。

If the data you're passing isn't sensitive information, then just go with the query string. If it is sensitive, think about encrypting either a session or cookie value that you can decrypt on the Page_Load of the ASPX.

如果您传递的数据不是敏感信息,那么只需使用查询字符串。如果敏感,请考虑加密会话或cookie值,您可以在ASPX的Page_Load上对其进行解密。

#1


1  

The only ways you'd be able to achieve that is either using session/cookies or the query string.

您能够实现这一点的唯一方法是使用会话/cookie或查询字符串。

If the data you're passing isn't sensitive information, then just go with the query string. If it is sensitive, think about encrypting either a session or cookie value that you can decrypt on the Page_Load of the ASPX.

如果您传递的数据不是敏感信息,那么只需使用查询字符串。如果敏感,请考虑加密会话或cookie值,您可以在ASPX的Page_Load上对其进行解密。