|
Setting the session expiry to a very large value is a bad idea. It means that your server ends up storing live session data for every user that has visited the site during the session expiry time.
The normal way to do this (auto login after a long idle time) is to use a cookie to skip authentication on coming back to the site.
Alternatively, you can use keep-alive AJAX requests to maintain a session while the user is actually still looking at the site (or at least has it open in a browser).
|
|
|
|
|
Hi BobJanova,
Thank you so much for your detail explanation,
|
|
|
|
|
My fancy new WD MyNet 900 Wireless Router periodically requires a reboot to establish an Internet connection with the rest of my devices. I know that Windows can detect when the network connection is lost, but I'd like to do so myself in C#, and trigger a reboot of the router via a hardwired network connection to an IP-enabled ac outlet that provides power to the router. Yeah, it's a kluge, but I like the router otherwise. It just likes to go to sleep sometimes.
I'm currently preparing an Iris-based home automation system, and the last thing I need is for it to be unable to call me when it needs to, just because this silly router has lost its way. Trouble is, I have no idea what to search for in the .Net documentation. Can anyone suggest a class that can monitor and fire an event when the network connection is lost on a wireless interface?
My thinking is, I can run a service on my main computer that monitors the wireless network connection. When it detects that the connection has failed, it cycles the power outlet for the router using a hardwired Ethernet network and waits for a minute to see if the wireless network is re-established. If not, it can try again as often as needed to fix the problem; I'd set some maximum number of retries before assuming that the ISP is sucking again and giving up. If I was willing to pay for it, I do have a couple of cellular modems I could then use to have it call the ISP over and over again until someone fixes the service, but that would cost a bit more than I'm willing to pay to Sprint. Still, it could be fun. But I digress...
Where should I be finding a function to detect a lost wireless connection? MSDN hasn't been much help tonight, but Google found a useful GetIsNetworkAvailable function in the System.Net.NetworkInformation namespace. Unfortunately, this call will return true even if the upstream Internet connection has been lost. The article stops just short of providing any useful information for handling that situation.
Will Rogers never met me.
|
|
|
|
|
|
Cool! That isn't exactly what I'm looking for, but I think it contains enough information for me to customize it. Thanks a bunch!
Will Rogers never met me.
|
|
|
|
|
What I did to manage things was to use the web-based command/status interface of the modem/router and some HTML parsing. For example, I get hourly reports of the ADSL line status (speed/attenuation/margin, up and down) this way, and I can reboot it by going to the appropriate URL (after logging in, of course)
27/11/12 15.00.34,12864 kbps,42.0 db,6.20 db,1020 kbps,20.5 db,7.0 db
27/11/12 16.00.34,12793 kbps,42.5 db,6.45 db,1020 kbps,20.5 db,7.0 db
I also set up a syslog daemon and got the modem/router to log everything. So when the telco tech called this moring to look at my line problems, I could show him logs like this:
2012-11-27 12:45:40 User.Emerg 172.19.243.1 [Internet disconnected]
2012-11-27 12:47:04 User.Emerg 172.19.243.1 [Internet connected] IP address: 101.174.189.211,
2012-11-27 12:59:55 User.Emerg 172.19.243.1 [Internet disconnected]
2012-11-27 13:01:16 User.Emerg 172.19.243.1 [Internet connected] IP address: 203.51.49.191,
2012-11-27 15:47:16 User.Emerg 172.19.243.1 [DHCP IP: (172.19.243.125)] to MAC address 00:1A:4B:62:40:3F,
Helps no end convincing them that there actually is a problem.
If you want any more along these lines, email me.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
Thanks, Peter!
Will Rogers never met me.
|
|
|
|
|
In the code snippet below when i try to check if column row is not equal to null is throw an error: System.NullReferenceException: Object reference not set to an instance of an object
SPList srcList = web.List["My List Name"];
foreach(SPListItem item in srcList.Items)
{
if((DateTime)item["Start Date"] != null)
{
//do something
}
}
|
|
|
|
|
zeqir85 wrote: if((DateTime)item["Start Date"] != null)
You do the typecast before you check if it's null. So it should be like this:
if((DateTime)item["Start Date"] != null)
By the way: as it's SharePoint you could use the SharePoint Board.
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Thank you very much. It works now.
|
|
|
|
|
Considering
(double)item["Start Date"]
would likely crash, perhaps
item["Start Date"] is DateTime
is a better alternative?
But then, I don't know anything about the sharepoint list object. Just assuming that it matches all other Microsoft enumerable collections.
|
|
|
|
|
Ennis Ray Lynch, Jr. wrote: perhaps
item["Start Date"] is DateTime
is a better alternative?
Yes. Definitely!
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Debugging is generally the best way to detect 'Object reference not set' errors.
Once you find where the error occurs, you can check why that particular item is null.
The problem / solution may not necessarily in this line but rather somewhere else.
|
|
|
|
|
My JavaScript sends a selected path, for example C:\files to com ActiveX, I catch it on C# like this:
[ComVisible(true)]
public string MyParam
{
get
{
return myParam;
}
set
{
myParam = value;
}
}
I then launch a program like this:
[ComVisible(true)]
public void LaunchPlayer()
{
Process.Start("wmplayer.exe", "ANYFOLDER");
}
The problem is that how do I launch the program so that it uses the current value on myparam on "ANYFOLDER"?
|
|
|
|
|
How about:
Process.Start("wmplayer.exe", MyParam);
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Damn, I tried that but I'll retry. This might have been an embarrassing question
|
|
|
|
|
Be careful of the little trap with long path names. If the pathname contains spaces then the entire string must be surrounded with double quotes, like:
string MyParam = "C:\\Users\\Joni_78\\My Backup Files";
Process.Start("wmplayer.exe", "\"" + MyParam + "\"");
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you that worked . One thing, I get the MyParam on JavaScript from Windows Media Center (window.external.MediaCenter.MediaContext.GetProperty("Name")), it is in form dvd:///G:/ANYFOLDER/ I know how to get rid of the dvd:/// in Js but how to do it in C# and even better if possible, is it possible to do it here?
string MyParam = "C:\\Users\\Joni_78\\My Backup Files";
Process.Start("wmplayer.exe", "\"" + MyParam + "\"");
|
|
|
|
|
This is just string manipulation. What you would do in C# is very much the same as in Javascript. You could do it when you save the string in your MyParam setter, or when you return it from the getter. Look at the String [^] class for details.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you
|
|
|
|
|
Need to do the following:
given a array 'a' of double of monotone increasing values and a given value I have to find the index in the array so that V<a[i] &&="" v<="a[i+1]," if="" v="a.Min()," then="" return="" 0,=""> a.Max() or V < a.Min() the return 100.
double[] a = new double[]{1,2,3,4}
I look for a function F so that for example (implementing whaat described above:
F[0.5] =100;
F[1] = 0;
F[2] = 0;
F[2.1] =1;
F[4] =3;
F[4.1] =100;
It can be done with for...loop of course. Is it efficent or it is better using LINQ or Array.FindIndex or...smarter solution? (if it is more efficent LINQ or Array.FindIndex, how to do it?)
|
|
|
|
|
TheGermoz wrote: is better using LINQ
No. Probably not anyway, but I'm unclear what you are trying to do.
|
|
|
|
|
100 is a stupid failure value. What if you have a 100 element array? -1 is traditional for 'not found' (see Array.IndexOf and the like).
I think your expected output is wrong ... if F[4] is 3 then F[2] must be 1.
Does
int F(double[] arr, int value){
return -1 + Array.FindIndex(arr, d => d >= value);
}
... do what you want?
|
|
|
|
|
yes sorry my error F[2] must be 1.
Yes is solve it. The only error is for F[1] should be 0 and not -1.
Is it more efficient Linq or BinarySearch?
modified 27-Nov-12 7:47am.
|
|
|
|
|
If the values are monotonically increasing, Array.BinarySearch[^] will probably be the most efficient way to find a particular value.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|