How can I encrypt my ValidationExpression in VB.net?
I'm very new to asp and vb.net, I've just learned about regular expression validation but one thing is bugging me: How can I hide my expression from being viewed on my source code?
The plan is to make a very simple 'login' type of page. I know this goes against all that is holy in this kind of operations, but it's just something I'd like to try out.
Also, after the expression has been validated, I want to load another page, 开发者_如何学PythonI was thinking of achieving this with:
<asp:TextBox ID="txtcp" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="CP Errada"
Display="Dynamic" ControlToValidate="txtcp" ValidationExpression="admin"></asp:RegularExpressionValidator>
and in vb:
If txtcp is validated then
Response.Redirect("mypage.aspx")
end if
But the syntax on this IF is obviously not right, any help would be great.
You can shrink the size of your Regex Validator by using the following.
<asp:TextBox ID="txtcp" runat="server" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" />
And then in your Code behind
Function Page_Load()
With RegularExpressionValidator1
.ErrorMessage="CP Errada"
.Display="Dynamic"
.ControlToValidate="txtcp"
.ValidationExpression="admin"
End With
End Function
Function SubmitButton_Clicked()
If Page.IsValid Then
Response.Redirect("mypage.aspx")
End If
End Function
Unfortunately you can't encrypt it since the whole point of validation is to use Client Side Javascript. It is bad (in fact VERY BAD) to use a regular expression to validate a username in the way that I 'think' you're doing it in your example. The right thing to do for you, honestly, is to just use the build in ASP.NET Membership Provider. It is seriously easy to learn, it's mostly secure by default, and best of all... it's "no Fuss, no Muss".
精彩评论