Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using MPRBSL.Helpers;
using System.ServiceModel.Activation;
using WebMatrix.WebData;
using System.Web;
namespace MPRBSL.WebServices
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class AuthenticationService : IAuthenticationService
public bool Login(string username, string password)
if (username != null && password != null && WebSecurity.Initialized && WebSecurity.Login(username, password))
HttpContext.Current.Session["UserName"] = username;
return true;
return false;
public bool IsLoggedIn()
return WebSecurity.Initialized && WebSecurity.IsAuthenticated && WebSecurity.CurrentUserName == (HttpContext.Current.Session["UserName"] as string);
public void Logout()
if (WebSecurity.Initialized)


I am having same requirement. I tried to use this code. The login is working fine. But I am not able to use isloggedin method. the session is returning null and isautenticated method is false in my case. Can you please help me further to use this method.

Thanks & regards,
Satinder Singh.

Will I need to make changes in IIS and enable SSL?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment