|
Hi,
I have a code in the login.aspx.vb that create a cache item with the information of the user.
When the cache item expired it make a CallBack. In the callback I want to sign out and
redirect to the login page. When it tries to redirect, I received an "Object reference not set
to an instance of an object." error because the System.Web.HttpContext.Current = nothing.
Here is the code in the login page code behind:
Private Sub MyCacheItemRemovedCallback(ByVal key As String, ByVal val As Object, ByVal reason As Caching.CacheItemRemovedReason)
If reason = Caching.CacheItemRemovedReason.Expired Then
Try
System.Web.HttpContext.Current.Response.Redirect("SignOut.aspx")
Catch ex As Exception
End Try
End If
End Sub
Private Function AlreadyLogin() As Boolean
Dim sKey As String = TextBox_Login.Text.Trim + TextBox_Password.Text.Trim
Dim sUser As String = Cache(sKey)
If (sUser = Nothing) Or (sUser = "") Then
Dim callBack As Caching.CacheItemRemovedCallback = New Caching.CacheItemRemovedCallback(AddressOf MyCacheItemRemovedCallback)
Dim SessTimeOut As TimeSpan = New TimeSpan(0, 0, 15, , 0)
HttpContext.Current.Cache.Insert(sKey, sKey, Nothing, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, callBack)
Session("CurrentUser") = TextBox_Login.Text.Trim + TextBox_Password.Text.Trim
Return False
Else
Label_ErrorMessage.Text = Constants.ERROR_LOGIN_USER_LOGGED_IN
Return True
End If
End Function
Thank you for your responses
|
|
|
|
|
javidot wrote: MyCacheItemRemovedCallback
This method will fire when the item is removed from the cache, but there wont be any request from the user at that time, it just like if you try to redirect the user to some place when the session times out, (the user couldnt know that)
You need to ask when the user the requests a page if the control is from the cache, if not, you redirect to login page
Alexei Rodriguez
|
|
|
|
|
Can you put an example on how to do this?
Also, there's a way to redirect to a page in this scenario?
Thanks
|
|
|
|
|
You can do something very similar to what you got here
Private Function AlreadyLogin() As Boolean
Dim sKey As String = TextBox_Login.Text.Trim + TextBox_Password.Text.Trim
Dim sUser As String = Cache(sKey)
If (sUser = Nothing) Or (sUser = "") Then
Dim callBack As Caching.CacheItemRemovedCallback = New Caching.CacheItemRemovedCallback(AddressOf MyCacheItemRemovedCallback)
Dim SessTimeOut As TimeSpan = New TimeSpan(0, 0, 15, , 0)
HttpContext.Current.Cache.Insert(sKey, sKey, Nothing, DateTime.MaxValue, SessTimeOut, System.Web.Caching.CacheItemPriority.NotRemovable, callBack)
Session("CurrentUser") = TextBox_Login.Text.Trim + TextBox_Password.Text.Trim
Return False
Else
Label_ErrorMessage.Text = Constants.ERROR_LOGIN_USER_LOGGED_IN
Return True
End If
End Function
If the first time you add something to the session, and session timeout is longer than the cache timeout, then when the cache value is nothing and session isnot nothing then it means that the cache item expired, there you can redirect the user to the login page with FormsAuthentication.RedirectToLoginPage or response.redirect("yourloginpage.aspx") or server.transfer
Alexei Rodriguez
|
|
|
|
|
Hello
I try to send mail with an excel attachment
after the user fill the appropriate data in the web page and click send mail
i should fill an appropriate format of an excel sheet and attach to this file with changes to the outlook.
everything go fine, but i don't want the user know anything about the excel file
i want him just see the outlook with the excel file attached
Any solution or help will be greatly appreciated
And thanks in advance
Assaf
|
|
|
|
|
I am using a FormView in my website. Everything is working fine but I want to know how to get the value of label4 in the code behind. The Label4 is bound to data in a SQL database. This label is located within the EDIT TEMPLATE in the formview..
How come everything in a formview is not able to be accessed programmicially?
|
|
|
|
|
Jacob Dixon wrote: How come everything in a formview is not able to be accessed programmicially?
It is, but you have to use the formview.findcontrol ("controlname") and cast it to the appropiate type
Alexei Rodriguez
|
|
|
|
|
Sweet! Thanks!
Are you talking about (Label)FormView1.FindControl("Label4").Text ?
Something like that?
|
|
|
|
|
Yes
Does it work?
Alexei Rodriguez
|
|
|
|
|
Sure does!
Label newLabel = (Label)FormView1.FindControl("Label4");
Thanks again!
|
|
|
|
|
I have a website which deals with the registration for users, while the an independent C# class which is used to interact through a small client.Is there anyway i can start this class along with webpages in the asp.net hosting, and that it can run all time like a service ?
|
|
|
|
|
Hi,
Just a suggestion.Why not you write that class in a web service and mark those methods as WebMethods. And configure the web service with your asp.net application. Then at the time you want, you may call the service and perform the required tasks.
FYI:
Here is a guide to create web services
http://www.15seconds.com/issue/010430.htm[^]
Hope this helps you.
Thx,
Gayani
|
|
|
|
|
I used to be able to double-click on a control, and it would add a method to the .vb file.
Now, it changes to Source view mode of the .aspx file, and adds a block with the method inside.
How do I change it back?
<div class="ForumSig">"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
</div>
|
|
|
|
|
I think you are using HTML controls ...
|
|
|
|
|
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Page3.aspx.vb" Inherits="ApplicationForm.Page31" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Software Install</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" /></div>
</form>
</body>
</html>
I did see what you were referring to in the help, though.
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
|
|
|
|
|
If you want to use the code behind model, when you add a page to your web site, select the place code in separate file checkbox
Alexei Rodriguez
|
|
|
|
|
I'm using VS 2005. On Add->Existing Item->Web Form, I don't get that option (checkbox), just the filename.
"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit..."
"There is no one who loves pain itself, who seeks after it and wants to have it, simply because it is pain..."
|
|
|
|
|
That option is not available when adding existing items
You should make the appropiate modifications by hand after adding the existing item to your project
Alexei Rodriguez
|
|
|
|
|
I want to set a timer, in my web application.
I am displaying some questions on a web page, i want to set a timer, such that, say after 120 seconds the can't answer the question (i want to disable the radio buttons).
So, how can i set a timer ?
|
|
|
|
|
you can use AJAX Timer Control
|
|
|
|
|
Abhijit Jana wrote: AJAX Timer Control
i am not able to find any example on AJAX Timer Control
those present here on codeproject are too big and complicated ...
Do you have any direct or simple example (or link) for AJAX Timer Control ???
|
|
|
|
|
Not sure if this is what you need but it may help...
Create a standard ASPX Timer control with an AJAX update panel.
...
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server" /><br />
<br />
<asp:Timer ID="tmrClock" runat="server" Interval="1000" OnTick="tmrClock_Tick"></asp:Timer><br />
<br />
<asp:UpdatePanel ID="updPnlClock" UpdateMode="Conditional" runat="server"><br />
<Triggers><br />
<asp:AsyncPostBackTrigger ControlID="tmrClock" EventName="Tick" /><br />
</Triggers><br />
<ContentTemplate><br />
<asp:Label ID="lblTime" runat="server" ForeColor="#B22222"></asp:Label><br />
</ContentTemplate><br />
</asp:UpdatePanel><br />
...
Code Behind Page:
Subscribe to the Tick event on the ASP Timer control. This one represents a ticking clock.
protected void tmrClock_Tick(object sender, EventArgs e)
{
lblTime.Text = DateTime.Now.ToLongTimeString();
}
|
|
|
|
|
tina- wrote: I want to set a timer, in my web application.
Use javascript setTimeout[^]. If you have AJAX server extensions installed and got AJAX toolkit DLL, you can try the timer control. It encapsulates the settimeout functionality.
|
|
|
|
|
I have an html page that loads inside an IFRAME. My html has a link to other page if I click it, the new page is loading inside the IFRAME. I want it to open in the page itself (not in new page).
Any Idea please!!
|
|
|
|
|