c# - simple asp.net login page -


i needed create simple fast login form internal company project i'm working on. saw this tut on how using vb - looked fast , easy. ran through converter change c# when load page, error get:

cs0103: name 'session' not exist in current context 

with following code:

<script runat="server">     public void login(object s, eventargs e)     {         if (tbusername.text == "admin" & tbpassword.text == "admin")         {             session("admin") = true;             response.redirect("dashboard.aspx");         }         else         {             session("admin") = false;             litlogin.visible = true;             litlogin.text = "<p>sorry have provided incorrect login details.</p>";          }     } </script> 

edit adding brackets helps on login page, on page im trying protect have check session this:

    <form id="form1" runat="server"> <script runat="server">     protected void page_load(object sender, system.eventargs e)     {         if (session["admin"] != true)         {             response.redirect("login.aspx");         }     }  </script> 

and throws cs0019: operator '!=' cannot applied operands of type 'object' , 'bool'

in c#, need use [and ] indexers.

in other words, replace

session("admin") 

with

session["admin"] 

in response edit:

if (session["admin"] != true) 

should cast bool, should try:

if (!(bool)session["admin"])  

(no need compare boolean value true/false)


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -