How do I setup ASP.NET MVC 2 with MySQL?

I’m assuming that you have Visual Studio Professional 2008, have access to an instance of MySQL server, and have moderate to advanced development experience. This MAY work with VS2008 Web edition, but not at all sure. If you haven’t, install MySQL Connector for .NET (6.2.2.0 at the time of this write-up) Optional: install MySQL GUI … Read more

How do I use my own database with SimpleMembership and WebSecurity? What is MVC4 security all about?

See the summaries below each quote for a quick answer, and the paragraphs for detail. Also see the References section at the end for the authoritative sources. Summaries 1.What is SimpleMembership/SimpleMembershipProvider (WebMatrix.WebData) and what is it/are they responsible for? SimpleMembership (a term that covers both the SimpleMembershipProvider and SimpleRoleProvider) is responsible for providing a clean … Read more

SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified [closed]

If you are connecting from Windows machine A to Windows machine B (server with SQL Server installed), and are getting this error, you need to do the following: On machine B: 1.) turn on the Windows service called “SQL Server Browser” and start the service 2.) in the Windows firewall, enable incoming port UDP 1434 … Read more

ASP.NET MVC 4 Web API Authentication with Membership Provider

You could use basic authentication with SSL. On the server side we could write a custom delegating handler which will verify the credentials by querying the memebership provider that we registered, and if valid, retrieve the roles and set the current principal: public class BasicAuthenticationMessageHandler : DelegatingHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) … Read more

ASP.NET authentication login and logout with browser back button

Worrying about the browser history and back button is going to give you headaches and genital warts. There are facilities built in to handle this problem. Your logout link/button should point to a page containing this code, along with whatever else you want. [vb.net] Imports System.Web.Security Private Sub Page_Load(ByVal sender As System.Object, ByVal e As … Read more

When the same user ID is trying to log in on multiple devices, how do I kill the session on the other device?

I came up with a pretty awesome solution to this. What I’ve implemented was when user “Bob” logs in from their PC, and then the same user “Bob” logs in from another location, the log-in from the first location (their PC) will be killed while allowing the second log-in to live. Once a user logs … Read more

Custom MembershipProvider in .NET 4.0

It’s very simple really: Create a new Class file (if you’re not using a multi-layered system, in your project’s Models folder) let’s called MyMembershipProvider.cs Inherit that class from System.Web.Security.MembershipProvider automatically create the needed methods (period + space in the inherit class) Done! All methods will have the NotImplementedException exception, all you need to do is … Read more

How to assign Profile values?

I had the same problem today, and learned a lot. There are two kinds of project in Visual Studio — “Web Site Projects” and “Web Application Projects.” For reasons which are a complete mystery to me, Web Application Projects cannot use Profile. directly… the strongly-typed class is not magically generated for you from the Web.config … Read more