哪个更适合在页面之间传递变量? QueryString VS C#类 [英] Which is better for passing variables between pages ? QueryString VS C# class

查看:108
本文介绍了哪个更适合在页面之间传递变量? QueryString VS C#类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Which is better for passing variables between pages ? QueryString VS C# class







为什么人们总是使用QueryStrings,这是一个糟糕的解决方案因为注入...如果这是真的idk。



为什么不只是C#类传递变量(用户名,userip等等) ..)



有什么区别:



- 性能

- 安全




Why people always use QueryStrings, it's bad solution cuz of Injection... idk if that's true.

why not just C# class to pass variables ( username, userip, etc... )

What's difference in :

- Performance
- Safety

推荐答案

好吧,我不认为人们总是使用查询字符串 - 我只将它们用于一些特定的事情,例如电子邮件确认和等等。 Google非常广泛地使用它们,但是大多数网站可能都没有。



你不能真正直接使用C#类在页面之间传递值,因为它们不是'在页面之间保留,并且没有直接传递它们的机制。相反,您可以使用Cookie或(更有可能)使用Session对象来存储数据并以这种方式传递。您可以创建一个C#类并将其放在Session中,但并不是严格需要的。
Well, I'd don't think "people always use" query strings - I only use them for a few specific things, such as email confirmation and so forth. Google uses them quite extensively, but most sites probably don't.

You can't really use a C# class directly to pass values between pages, because they aren't preserved between pages, and there is no mechanism to pass them directly. Instead, you would use either Cookies or (more likely) the Session object to store your data and pass it that way. You could create a C# class and put that in the Session, but it isn't strictly needed.


QueryStrings不仅对网站有害(因为所有内容都附加到URL上)很长...有些浏览器喜欢短网址,对SEO也不好。您应该考虑生成网址,例如 http://www.example.com/page/param_value



其次,既然你在说话关于ASP.NET,ASP.NET提供了许多传递值的方法,其中,如果数据仅存在于该Session并且不需要维护,则Sessions是更好和更精细的传递值的方法即使用户关闭了浏览器。



如何使用ASP.NET在不同网页之间共享数据 [ ^ ],在很多方面,建议使用会话变量。但请记住,不要将敏感信息存储在Cookie或任何其他存储机制中。当您想要共享敏感权限(如信用卡信息或密码详细信息)时,请始终使用令牌。
QueryStrings are not just bad for the websites (because everything is appended to the URL making it long... Some browsers prefer short URLs), it is also bad for SEOs. You should consider generating URLs like, http://www.example.com/page/param_value.

Secondly, since you are talking about ASP.NET, ASP.NET provides many ways of passing the values, of which, Sessions are much better and fine-tuned ways for passing the values if the data is only going to exist for that Session and does not require to be maintained even if user closes the browser.

How to share data among different web pages using ASP.NET[^], in many ways, Session variables are much recommended to be used. But remember, do not store sensitive information in Cookies or any other storage mechanism. Always use tokens when you want to share the sensitive permissions like credit card information or password details.


注意在页面之间,同一页面的实例之间传递数据的新方法重新加载后:网络存储:

网络存储 - 维基百科,免费的百科全书 [ ^ ],

Web Storage API - Web API | MDN [ ^ ],

使用Web Storage API - Web API | MDN [ ^ ]。



它有很多好处。它是最通用的,因为它不依赖于您在服务器端的内容,即使您根本不使用HTTP服务器也能正常工作。它重量很轻,不会消耗任何流量。



-SA
Pay attention for the newer way of passing data between pages, of between the instances of the same page after reloading: Web Storage:
Web storage — Wikipedia, the free encyclopedia[^],
Web Storage API — Web APIs | MDN[^],
Using the Web Storage API — Web APIs | MDN[^].

It has many benefits. It's the most universal because it does not depend on what you have on the server side and works even if you don't use an HTTP sever at all. It is very light weight and does not consume any traffic.

—SA


这篇关于哪个更适合在页面之间传递变量? QueryString VS C#类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆