1

i edited the question

it still does not work, the user writes appendix then press OK in Login, nothing happens

here is the login (vb.net)

Partial Class login
Inherits System.Web.UI.Page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Session("passcode") = TextBox1.Text
    Response.Redirect("Default.aspx")

End Sub
End Class

and here is the default page C#

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    if (Session["passcode"] == "appendix")
    {
       Response.Write("OK !");
    }
    else
    {
        Response.Redirect("login.aspx");
    }
}


}
statmaster
  • 1,229
  • 9
  • 14

2 Answers2

9

You probably mean

Session["passcode"] == "Appendix"

In C# (unlike VB), == is the equality operator and = is the assignment operator.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
  • Or maybe `Session["passcode"].Equals("Appendix")` Or `Session["passcode"].Equals("Appendix", StringComparison.CurrentCultureIgnoreCase)` – immutabl Dec 20 '10 at 12:30
  • @5arx: The former will fail if the session variable is null, which is unlikely to be the intent. `Session` indexer is of type `object`. You have to cast it to `string` to use the latter overload of `Equals`. In both cases, `"Appendix".Equals` will resolve the problem with `null`. – Mehrdad Afshari Dec 20 '10 at 12:32
  • @Mehrdad - Agreed. I would always check for a null session variable first. "Omitted for brevity" :-) – immutabl Dec 20 '10 at 12:41
  • @statmaster: you may wanna look at something like http://stackoverflow.com/questions/873207/force-download-of-a-file-on-web-server-asp-net-c/873228#873228 – Mehrdad Afshari Dec 20 '10 at 13:06
  • @Mehrdad : my old proble still exist ! i have no problem with export to excel – statmaster Dec 20 '10 at 13:14
1

Cast the object type value to a string

((string)Session["loggedInUserType"]) == "Administrator"

Refer here

Community
  • 1
  • 1
user9371102
  • 1,278
  • 3
  • 21
  • 43