HTML | CSS | JavaScript | ASP.NET | PHP | C# | Java | VB.NET | MS SQL | MySQL | Flash
admin
This user hasn't shared any biographical information
Posts by admin
Microsoft PDC 2008 Sessions are online!
Nov 24th
I just wanted to make a quick post about this. If you want to know what’s going on in Microsoft these days when it comes to their developer platform, then you would want to check out some of these online sessions from the PDC conference last month. I have found some of these sessions to be very informative and I’m a little excited to see what is coming within the next 2 years. Anyways, just wanted to share this with you. Until next time…
Happy Coding!
Detecting Session Timeouts using a ASP.Net MVC Action Filter
Nov 23rd
Some time ago, I read an article on how to detect a session timeout in a ASP.Net Web forms application by placing some code in a Base Page. The code worked for me and you could read more about it here. In my last post I mentioned that Microsoft released a beta version of their MVC implementation of ASP.Net and since them, I have been playing around with it. But, as with Web forms, I still needed a way to detect a session timeout and perform an action when a timeout is detected. So, I decided to use the same code implemented in the original article and implement it into my MVC project. I decided to write a custom action filter and apply it to my controller actions where I need to ensure that my session was still active. Here is the code for my action filter.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Reflection;
namespace Web {
public class SessionExpireFilterAttribute : ActionFilterAttribute {
public override void OnActionExecuting( ActionExecutingContext filterContext ) {
HttpContext ctx = HttpContext.Current;
// check if session is supported
if ( ctx.Session != null ) {
// check if a new session id was generated
if ( ctx.Session.IsNewSession ) {
// If it says it is a new session, but an existing cookie exists, then it must
// have timed out
string sessionCookie = ctx.Request.Headers[ "Cookie" ];
if ( ( null != sessionCookie ) && ( sessionCookie.IndexOf ( "ASP.NET_SessionId" ) >= 0 ) ) {
ctx.Response.Redirect ( "~/Home/Login" );
}
}
}
base.OnActionExecuting ( filterContext );
}
}
}
And then, I would apply this filter to my Controller action methods like so:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
namespace Web.Controllers {
public class HomeController : Controller {
[SessionExpireFilter]
public ActionResult Index( ) {
// This method will not execute if our session has expired
// render Home Page
return View();
}
public ActionResult Login() {
// render Login page
return View();
}
}
}
The code is pretty straightforward. I just apply the [SessionExpireFilter] attribute on each method where I want to ensure that our session is still valid. If you have any questions, leave a comment under this post. Until next time…
Happy Coding!
ASP.NET MVC Beta Released!
Oct 16th
Scott Gu has all the details. I’ve been waiting for the beta release before I really started digging into this MVC framework. I am a Web Forms guy; but I have been waiting for a “structured framework” to come instead of dropping controls on a page and writing UI code behind each page. Based on all of the reading that I have seen, I like what I see.
For a purely web forms developer, which I am not, don’t expect to get all the fancy controls like GridViews, Validation controls, Login Controls, etc, like you would get out of the box in a web forms project. With ASP.NET MVC, HTML is your friend and if you are intimidated by writing HTML, then you probably shouldn’t be a web developer in the first place. However, this is the concept of HTML Helpers that you can use to assist you in generating pretty much all of the HTML input controls just by using some script code; but it is not mandatory.
So, this will be a breath of fresh air for me. I am working on a project now and I will be developing it using the MVC framework. I like working with new stuff and hopefully I will be able to share my experience as I go along. Until next time…
Happy Coding!
Heartache! Microsoft to cancel Seinfeld ads
Sep 18th
I never thought they were that good anyway. At times, it was very hard to catch the joke and if you compare it to the Apple commercials, there was a big, big difference.
http://valleywag.com/5051455/microsoft-to-announce-jerry-seinfeld-ads-cancelled-tomorrow
Until next time…
Happy coding!
FYI…
Sep 14th
I’m still alive. Yes, I haven’t posted anything in a while; but that’s just because I have had a lot going on. I’m working on a few projects and I took a vacation recently, so I guess that explains it. I’ve been learning some new stuff for a change and once I get something together I’ll give you a quick update on it. Until next time…
Happy coding!
Traffic Light Simulation using the Basic Stamp 2
Jul 10th
So, it took me long enough right? I know in my last post I left off by saying that I would try to have at least 1 project that is build with the Basic Stamp 2 and include it on my next post. I came up with a Traffic Light simulation which I thought was a very practical application and I am very confident that everyone reading this blog is familiar on how a traffic signal works.
Initially, I thought about posting screenshots of the Homework Board circuit; but I felt that these types of projects would be best to demonstrate with a video.
Here is the circuit schematic that I have constructed using ExpressPCB which is absolutely FREE!
As you can see, the connections on the left represents the I/O pins of the Basic Stamp. Then there is a series connection of a 220 ohm resistor and the LED for the traffic signals and cathode or the minus (-) or the flat end of the LED is connected to GRND. I think it’s worth mentioning that when an I/O pin goes HIGH each circuit would have a source voltage of +5 volts and when the I/O pin goes LOW then the source voltage goes down to 0 volts. In this circuit configuration, the LED is configured as Active High which means that when I send a HIGH signal to an I/O pin, the LED is turned on and a LOW turns the LED off. According to the documentation for the Basic Stamp, each I/O pin can only source up to 20 mA of current if only 1 pin is connected to a circuit. However, if we are using a group of pins, we can only source up to 40 mA. So, we have to be careful not to supply our circuit with too much current or we can risk damaging our Basic Stamp that is the reason I included a 220 ohm resister to limit the current flowing through the circuit. Also, take into the account that the Basic Stamp Homework Board has built-in 220 ohm resistors as a safety feature but I didn’t want to take any changes so I added my own. But, if you don’t decide to use the resistor, then you LED would light up more brightly than in the video. Good. That is out of the way.
Ok. Now here is the code that I used to get all of this done. Remember, the Basic Stamp is programmed using PBASIC so the code should be very easy to read.
' ========================================================================= ' {$STAMP BS2} ' {$PBASIC 2.5} ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' SIMPLE TRAFFIC LIGHT CIRCUIT SIMULATION ' Traffic Light Transition: ' RED ' GREEN ' YELLOW ' -----[ I/O Definitions ]------------------------------------------------- RedLED PIN 15 YellowLED PIN 10 GreenLED PIN 5 RedDuration CON 20000 '-- 20 sec GreenDuration CON 20000 '-- 20 sec YellowDuration CON 10000 '-- 10 sec ' -----[ Constants ]------------------------------------------------------- ' -----[ Variables ]------------------------------------------------------- ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: ' -----[ Program Code ]---------------------------------------------------- Main: DO '-- turn only Red light on for 20sec HIGH RedLED LOW YellowLED LOW GreenLED PAUSE RedDuration '-- turn only Green light on for 20sec LOW RedLED HIGH GreenLED PAUSE GreenDuration '-- turn only Yellow light on for 10sec LOW GreenLED HIGH YellowLED PAUSE YellowDuration LOOP END ' -----[ Subroutines ]-----------------------------------------------------
Hopefully, the code is strait forward. As you can see I set up some variables to hold the numbers of the I/O pins I am using. Then I have some variables to represent the duration that each LED will be turned on. Then if you jump down to the main body of the code, you would see that this code would run in a continuous loop and will never end until the battery is disconnected or runs out.
Then, you can see that I first turn on the Red LED by sending a HIGH to that I/O pin while setting all the other pins to LOW. Then I pause for the duration specified in the variable and then everything else is pretty cut and dry. I just turn on and off the other lights in the sequence that I want. Pretty simple huh?
Hopefully, this was helpful to you and you can see how easy Microcontrollers are to work with these days. I welcome any questions or comments you may have. Until next time…
Happy Coding!
What I have been up to lately…
Jun 28th
What is this? It’s a Basic Stamp Microcontroller board that is manufactured by Parallax, Inc. Some of you may not know; but I originally got started with Programming as a Electronics Engineering student in college. Electronics was my first love. However, when I graduated the market demands were for programmers and not electronic engineers so I decided to go where the demands were. This was over 6 years ago and I pretty much forgot everything, so I figured I would re-teach myself the basics of electronics and learn how to program microcontrollers in the process. I did have some experience programming the Motorola 68000 which were found in the early Apple computers. But, I wanted something that was a little easier to set up and have a better programming environment. The 68000 chip had to be programmed using Assembly Language and a EEPROM programmer. But of course, I didn’t want to go back to using Assembly Language after writing C# for all these years. To program the Basic Stamp all you need is a PC and a serial port. I do have to learn a new language called PBASIC, which looks as feel a lot like the original BASIC language. To start of with, I would advise anyone to purchase the Basic Stamp Activity Kit as it includes everything (except the 9V battery) you need to get started with. The documentation is very easy to read and they have a great forum you can use to post any questions that you may have.
In my next post, I would like to have at least 1 project completed and I will take some pictures of the circuit board layout and post the code for you to see how easy it is. Obviously, the more complex circuit you have, the more code you have to write. So, I will start off with something simple. Hopefully, this post has inspired you to start a new adventure in any area of your life. This is one adventure that I hope I can keep up with until something else comes along
. Until next time…
Happy Coding!
ASP.NET and Password TextBox with initial value
May 23rd
Some asked me a question the other day about an issue they were experiencing with pre-loading a password text box with some initial text. Here is what their code looked like:
ASPX
<asp:TextBox id="txtPassword" runat="server" TextMode="Password" />
Code-Behind
txtPassword.Text = "mypassword";
But, when the page loaded, there was no value contained in the password text box. So, what’s the issue? Apparently, this is a restriction that the ASP.NET developers thought that should be in place due to security reasons. However, a workaround for this is to add the value to the attributes collection of the web server control:
txtPassword.Attributes.Add("value", "mypassword");
Doing this would cause the Value attribute of the <input type="password"> HTML control to be populated. So, here is what will be sent to the browser for rendering:
<input type="password" id="txtPassword" name="txtPassword" value="mypassword" />
It should be noted that even though the value of the password will be masked in the browser, the value will show up in clear text if you view the page source. So, if this is not the behavior you would like to have, then this is not the solution for you. Hopefully, this was of some help to you.
Until next time…
Happy Coding!
My Experience with Visual Studio 2008 Remote Debugging
Apr 14th
Surprisingly, it’s been quite pleasant. I have tried Remote Debugging with VS.NET 2003, and I didn’t have much luck with it. However, last week there was a scenario where I desperately needed it and given that we have upgraded to VS 2008, I thought I should give it another try. There is two steps I had to perform to get this to work correctly:
- Configure your client machine using the Remote Debugger Configuration Wizard.
- Copy the Remote Debugger server components to the remote machine
That’s it. Ok. I didn’t give you much here, so here is some more detail.
To run the Remote Debugger Configuration Wizard go to:
Start -> Program -> Microsoft Visual Studio 2008 -> Visual Studio Tools -> Visual Studio 2008 Remote Debugger Configuration Wizard
The wizard will begin and you will be brought to this screen:
This screen is basically asking if you want to run the remote debugger as a Windows Service. For me, I didn’t check the box to run as a service and it’s probably not even necessary. There is nothing much else to do but to click Next until the wizard completes. At the end it will tell you that all the necessary ports (most likely TCP) were opened and ready to connect to remote machines.
To run the server components on the remote machine, you need to copy the contents of this folder to the remote machine.
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Remote Debugger\x86
Once copied to the remote machine you will just have to run the msvsmon.exe program. The main window would look like this when it’s ready to accept incoming connections:
Play close attention to the server name listed in the entry. This is the name you will need to enter into the Qualifier field in the Debug -> Attach to Process screen inside Visual Studio when you want to begin the debugging process.
Remember to set your breakpoint first and attach to the process you want on the remote machine. The process you will want to debug should be listed in the Available Processes list.
One thing to watch out for is that in my setup, my username and password on my client machine and my remote machine were kept in sync. This way I don’t run into any unexpected access/permissions issues when connecting to the remote machine. I would also note that I was an Administrator on both machines so this would rule out any permission issues.
Let me know if you found this helpful. I do appreciate how the Visual Studio tools team simplified this process to it is as easy as following the 2 steps I listed above.
Until next time…
Happy coding!
I'm Back!!
Mar 22nd
So, based on my last post you could probably tell that I’ve been quite busy lately. It’s been over 2 months now and Keira is doing wonderful. She just got her shots yesterday and now we could start taking her out a few places. Having said that, I have plans to begin posting again at least once a week. I apologize for that long, long commercial break; but it was necessary and worth it. Here is the most recent photo of her. She is now 9 lbs 4oz and looking beautiful.
