简体   繁体   English

Webmatrix-将变量从cshtml页传递到aspx页

[英]Webmatrix - Passing variable from cshtml page to an aspx page

I'm using Webmatrix to build my site which renders different fusioncharts when users click on different buttons, ie 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构建我的网站,当用户单击不同的按钮时,该网站将呈现不同的融合图,即,如果单击“欧洲”按钮,则将获得欧洲平均温度图,如果单击美国,则美国平均温度等等...

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,并且如果该用户单击按钮,则if(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”的文件,该文件又创建了一个XML文件,该文件由在ms sql数据库上执行存储过程来填充,如下所示:

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页面的代码中,我可以轻松地调用USERID变量,因为它是使用MembershipUser user = Membership.GetUser();的会话变量MembershipUser user = 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”的变量传递给aspx页,以便在等待AREA变量的存储过程中使用?

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. 如果敏感,请考虑加密可以在ASPX的Page_Load上解密的会话或cookie值。

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

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