B
Ben
Hi,
i don't use the heavy login control of asp.net but only a simple login
/password in order to identify the users.
In directory App_Code, i put a file (check.vb) with this content:
Public Class check
Public Shared Sub beh()
Dim ok As HttpCookie
ok = HttpContext.Current.Request.Cookies("ok")
If Not ok.Value = "y" Then
If ok.Value = Nothing Then
Dim jv As String
jv = "<script language='javascript'>" _
& " alert(First log in please');" _
& " window.location.href='log.aspx';" _
& "</script>"
HttpContext.Current.Response.Write(jv)
End If
End Sub
End Class
In every page of the application, i put this:
-----------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
check.beh()
....
End class
The log.aspx file contains this:
-----------------------------
Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Submit1.ServerClick
Dim beh, pw As String
Dim ok As New HttpCookie("ok")
beh = Text1.Value
pw = Password1.Value
If pw = "a" And beh = "a" Then
ok.Value = "y"
Response.Cookies.Add(ok)
Response.Redirect("menu.aspx", False)
Else
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert(wrong login /pw);", True)
End If
End Sub
No error appears when logging, but if i try to start e.g. file menu.aspx by
typing it in the browser (http://myserver/myapp/menu.aspx), i get the error:
"Object reference not set to an instance of an object" at line: check.vb
Remark: if i put the entire code from check.vb in file menu.aspx, i get the
javascript alert and i'm redirected to log.aspx, with other words, it works.
So, why doesn't the code work when put into a shared sub but works when put
directly into the file?
Thanks for help.
Ben
i don't use the heavy login control of asp.net but only a simple login
/password in order to identify the users.
In directory App_Code, i put a file (check.vb) with this content:
Public Class check
Public Shared Sub beh()
Dim ok As HttpCookie
ok = HttpContext.Current.Request.Cookies("ok")
If Not ok.Value = "y" Then
If ok.Value = Nothing Then
Dim jv As String
jv = "<script language='javascript'>" _
& " alert(First log in please');" _
& " window.location.href='log.aspx';" _
& "</script>"
HttpContext.Current.Response.Write(jv)
End If
End Sub
End Class
In every page of the application, i put this:
-----------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
check.beh()
....
End class
The log.aspx file contains this:
-----------------------------
Protected Sub Submit1_ServerClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Submit1.ServerClick
Dim beh, pw As String
Dim ok As New HttpCookie("ok")
beh = Text1.Value
pw = Password1.Value
If pw = "a" And beh = "a" Then
ok.Value = "y"
Response.Cookies.Add(ok)
Response.Redirect("menu.aspx", False)
Else
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(),
"myscript", _
" alert(wrong login /pw);", True)
End If
End Sub
No error appears when logging, but if i try to start e.g. file menu.aspx by
typing it in the browser (http://myserver/myapp/menu.aspx), i get the error:
"Object reference not set to an instance of an object" at line: check.vb
Remark: if i put the entire code from check.vb in file menu.aspx, i get the
javascript alert and i'm redirected to log.aspx, with other words, it works.
So, why doesn't the code work when put into a shared sub but works when put
directly into the file?
Thanks for help.
Ben