What is equivalent for below code in VB.NET
new FormsAuthentication().SetAuthCookie(user.UserId, true, ticketData);
Ref: http://blog.tatham.oddie.com.au/2011/04/04/released-formsauthenticationextensions
For starters SetAuthCookie is a static method, so you shouldn't be creating any instance of FormsAuthentication . So the correct way to do this in C# is the following:
FormsAuthentication.SetAuthCookie(user.UserId, true, ticketData);
and in VB.NET the following:
FormsAuthentication.SetAuthCookie(user.UserId, True, ticketData)
Conclusion: almost the same. If you are following VB.NET conventions you would probably write True
instead of true
and get rid of the ;
.
If it were legal, the equivalent code in VB.NET would be the following (note the Call
in the beginning -- that's the magical part that makes this work):
Call (New FormsAuthentication()).SetAuthCookie(user.UserId, true, ticketData)
Another option would be use With
:
With New FormsAuthentication()
.SetAuthCookie(user.UserId, true, ticketData)
End With
But as Darin has said, SetAuthCookie()
is a static method and should be called as such.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.