简体   繁体   English

ASP.NET中的CustomerId和Request.QueryString

[英]CustomerId and Request.QueryString in ASP.NET

Request.QueryString is not very safe. Request.QueryString不是很安全。 Incase someone is logged in. Just by typing in the URL 有人登录。只需键入URL即可

myaccount.aspx?custId=10

One can get the information of another Customer. 人们可以获得另一个客户的信息。

So its not safe at all. 所以它根本不安全。 The reason for posting this was because, I wanted an alternative way of passing customerId between pages. 发布这个的原因是因为,我想要一种在页面之间传递customerId的替代方法。 Perhaps encrypt it? 或许可以加密吗?

Query strings are safe and are not flawed . 查询字符串是安全的没有缺陷

What is flawed and unsafe is trusting user input data. 有缺陷和不安全的是信任用户输入数据。 It is your responsibility to verify the data being sent to the server is not malicious and that the requested action is allowed for the logged in user. 您有责任验证发送到服务器的数据不是恶意的,并且允许登录用户请求的操作。

You should take that query stirng value, make sure it is the valid type (your example appears to be an integer) and then before fetching the customer's data, make sure the user is allowed to access that customers data. 您应该获取该查询的stirng值,确保它是有效类型(您的示例似乎是一个整数),然后在获取客户的数据之前,确保允许用户访问该客户数据。

Really for myaccount.aspx you shouldn't need to a user to pass their ID in as a parameter. 实际上,对于myaccount.aspx,您不需要用户将其ID作为参数传递。

As others have said, use Membership. 正如其他人所说,使用会员资格。 Or create a hash (an encypted value) of a user's ID and password and save that as a cookie or in the session object. 或者创建用户ID和密码的哈希值(加密值),并将其保存为cookie或会话对象。 You can read that instead of an input parameter. 您可以读取它而不是输入参数。

That's not the responsibility of the QueryString . 这不是QueryString的责任。 You should implement an authenication and authorization system, preferably with a MembershipProvider and RolesProvider . 应该实现一个身份验证和授权系统,最好使用MembershipProviderRolesProvider

It does what it's supposed to do. 它做了它应该做的事情。 It is up to you to secure your site. 您可以自行保护您的网站。 No one said everything in the querystring is used for sensitive access related functionality. 没有人说查询字符串中的所有内容都用于敏感访问相关功能。

There is no safe way to pass it. 通过它没有安全的方法。 Once the user has logged in, store the ID in Session or something equivalent, then always take it from there. 一旦用户登录,将ID存储在Session或等效的内容中,然后始终从那里获取。

您可以查看asp.net会员资格

您应该使用ASP.NET 安全性对客户进行身份验证和授权,以便检查登录用户是否可以访问查询字符串中指定的客户ID。

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

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