Getting Forms Authentication Timeout from web.config programmatically
I have to create Forms Authentication ticket's on my own for some parts of a web application. I won't get into the why as it's a bit complicated, so trust when when I say that I need to.
I wanted to rely on defaults as much as possible so when I went to set the default timeout I was astounded to find that it wasn't available easily through code. I didn't just want to hardcode the value of '30' minutes because it can be overridden in the web.config.
So I hit Google figuring someone's run into this before, and they had with no better conclusion. Scott Hanselman listed a whole bunch of methods that were attempted but failed and eventually ended up using xpath to access the value directly from the file. That's 2004, 5 years ago, I figured there had to be a better way.
I ran to Reflector and looked at how the forms authentication timeout is initialized in the first place.
AuthenticationSection authentication = RuntimeConfig.GetAppConfig().Authentication; ... _Timeout = (int)authentication.Forms.Timeout.TotalMinutes;
It just loads the config section and accesses it directly. Nothing really preventing me from doing just that. A little extra help on accessing the System.Web section from dotnetcurry.com and here is what I came up with:
Configuration config =
WebConfigurationManager.OpenWebConfiguration( "~" );
AuthenticationSection authentication =
(AuthenticationSection)config.GetSection(
"system.web/authentication" );
return (int)authentication.Forms.Timeout.TotalMinutes;As an added bonus, even if the Timeout isn't specified in the web.config, it will return the default of 30 minutes. Add some error handling for the cases with the section or value are not present and voila.
Nearly Holey
I like to introduce this story to my friends with the phrase, "I was almost shot!" This usually gets their attention. I'll admit that it is almost a false pretense. Looks like you'll have to read on.
I was in Seattle with my friends Chris and Capi, we decided a pub crawl was the best way to cap off a round of interviews. A crawl that ended in the supposedly less-than-savoury neighbourhood of Beacon Hill at The Beacon.
The story doesn't end here, I did say 'almost shot.'
Read more...X markiert die Stelle
The last time that I can remember being hopelessly lost was absconding from the scene of a police-crashed bush party. That's another story from my youth though, this one takes place while hiking through the Valley of Fire in the Nevada desert.
This misbegotten adventure began when I met Lothar, a German photographer. He was raving about a relatively unknown arch, the Ephemeral Arch, found quite far off the beaten path. Intrigued I asked how to find it, naively assuming that he could point it out on the complementary park map that had the resolution of brown crayon and napkin. His instructions detailed every stop, direction, pass, path and landmark on the route in what I can only assume is perfectly understandable and grammatically correct German, enhanced brilliantly by grainy, greyscale photos of red rocks (highly distinguishable in a valley full of red rocks) . Looking at the encrypted treasure map, the pictures and my perfect-for-hiking-slip-on office shoes, I probably should have bailed.
Read more...Krewe of St. Anne's Parade
By far the most awesome Mardi Gras parade is the St Anne's parade. As far as I understand this an informal parade by the residents of Marigny and Treme; and is the only parade to take place in the French Quarter.
Tour de Bauchery Begins
The Tour de Bauchery begins, first stop New Orleans, Lousiana. Itinerary includes:
- Party on Bourbon St (yes it is Mardi Gras)
- Eat really Lousiana food
- Drive the Lake Ponchartrain causeway
- See the cemetaries
- etc....
Stranded.
It is a Saturday, in the industrial area outside of Guelph and I am the only one at work. It had been raining on and off but the big she storm came suddenly. Being the sort who finds the chaos and havoc of a good thunder storm oddly calming, I wandered out the back entrance out the back door and into the glassed in foyer area where I could watch the rain coming down for a little while.
I calmly and surely walked right out the back door and enjoyed five peaceful minutes of storm watching. Relaxed I decided it was time to get back to the grind and I reached for the door. That nagging sinking feeling that accompanies slow realization tickled my stomach, then as the door stood fast against my pulling full realization dawned upon me.
Weekends... Automatic locks...
Read more...
















