Using multiple membership providers within ASP.Net MVC 3 application

There is actually very little headache involved. Simply add all the MembershipProviders you want in web.config: <membership defaultProvider=”MembershipProvider1″> <providers> <clear/> <add name=”MembershipProvider1″ type=”MvcApplication.MembershipProvider1″ /> <add name=”MembershipProvider2″ type=”MvcApplication.MembershipProvider2″ /> <add name=”AspNetSqlMembershipProvider” type=”System.Web.Security.SqlMembershipProvider” connectionStringName=”ApplicationServices” /> </providers> </membership> As you can see I have added two providers. I have also specified a default provider. I can then switch … 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

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

How does the Authorize tag work? – ASP.NET MVC

The Authorize tag uses all the built in membership checks from ASP.NET. It’s VERY easy to roll your own tag. For example: public class MyAuthorize : AuthorizeAttribute { protected override bool AuthorizeCore(HttpContextBase httpContext) { if (httpContext == null) throw new ArgumentNullException(“httpContext”); // Make sure the user is authenticated. if (httpContext.User.Identity.IsAuthenticated == false) return false; // … Read more

How to obtain a list of Users from ASP.NET Identity?

I found out that I wasn’t using the derived ApplicationUser object for anything, so I just went ahead and changed all uses of it for plain old User. Then I just changed ApplicationDbContext definition for the following: public class ApplicationDbContext : IdentityDbContext< User, UserClaim, UserSecret, UserLogin, Role, UserRole, Token, UserManagement> { } And now I … 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

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)