Sunday, September 16, 2012
JavaScript Error – Submit is not a Function
If you get the JavaScript error “Submit is not a Function” then you are probably trying to call the Form’s Submit() Method, but you also have a button whitch is called Submit. This results in a conflict in the JavaScript becuse the Submit Method is already bound to the button.
The Solution is simply to change the name of the button so that name=”newname” (or what ever you prefer).
Labels:
HTML,
JavaScript,
Web Design,
Web development
Sunday, September 9, 2012
C# accessing or copying files over a network that requires authentication
I was working on a project with the requirement that I copy files over a network connection that needed username and password authentication. The big problem that I found was that the .NET framework did not natively expose the win32 API needed to do this, so I had to write my own wrapper using P/Invoke.
You can learn more about P/Invoke on MSDN or check out the pinvoke.net wiki for tons of great resources.
Here is the class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;
namespace MyAppName
{
Public class SoddingNetworkAuth : IDisposable
{
[DllImport("advapi32.dll", SetLastError=true)]
Private static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);
[DllImport("kernel32", SetLastError = true )]
Privatestaticexternbool CloseHandle(IntPtr hObject);
Private IntPtr userHandle = IntPtr.Zero;
Private WindowsImpersonationContext impersonationContext;
Public SoddingNetworkAuth(string user, string domain, string password)
{
if ( ! string.IsNullOrEmpty( user ) )
{
// Call LogonUser to get a token for the user
Bool loggedOn = LogonUser( user, domain, password,
9 /*(int)LogonType.LOGON32_LOGON_NEW_CREDENTIALS*/,
3 /*(int)LogonProvider.LOGON32_PROVIDER_WINNT50*/,
Out userHandle );
if ( !loggedOn )
throw new Win32Exception( Marshal.GetLastWin32Error() );
// Begin impersonating the user
impersonationContext = WindowsIdentity.Impersonate( userHandle );
}
}
Public void Dispose()
{
if ( userHandle != IntPtr.Zero )
CloseHandle(userHandle );
if ( impersonationContext != null )
impersonationContext.Undo();
}
}
}
Then you consume the class as follows
using (new SoddingNetworkAuth(@"UserName", @"ServerName", @"Password"))
{
//Do something
}
It’s that easy!
Let me know if this class helped or even if I just got you pointed in the right direction to solve your own unique problem.
Labels:
advice,
ASP.NET,
authentication,
C Sharp,
P/Invoke,
Web development
Saturday, September 1, 2012
A New Job and A New Focus
I would like to start by apologizing for not posting on this blog for such a long time, I have just started a new job in a new city and I’ve been hellishly busy as a result.
The New Job
This all happened because I was getting complacent at my old job, having been there for 13 years, and was not growing as a developer. At the same time, I was suddenly inundated with recruiters desperate for a senior software developer. At first I was just going to interviews to find out what was available and how it compared, but I soon realized that I had fallen behind on the technology that people are using for software development.
As a self taught developer, I have been wanting a mentor to help me grow my skills to become a better developer for a long time. I was also a jack of all trades in my old job; handling SEO, documentation, support, and project management over and above software development. So when I found a great development orientated company that didn’t care about my lack of qualification, and people that I really clicked with, I decided to jump at the opportunity.
The new job was in another city, but I have family there so, at the risk of sounding like a Will Smith song, I packed my bags and moved in with my Aunt and Uncle in Durban, and that's the story of how my life got turned upside down, and I became a senior developer at my new job.
The New Focus
What this all means for you dear reader, is that I will be changing the focus of this blog to deal primarily with C# and ASP.NET development. I will still leave my old SEO post up, but I really can be bother with trying to keep up will all of Google’s changes and new Metrics.
I would also like to take this opportunity to encourage you to take a look at your career and ask yourself if you have gotten stuck in a rut because you are just too comfortable. Are you still learning and growing, or have you allowed yourself to get into a dull routine?
Labels:
advice,
ASP.NET,
Web development
Subscribe to:
Posts (Atom)



