problem with webservice using formsauthentication

H

Heron

Hi,

I'm trying to consume a webservice on my website that uses
formsauthentication. Everything works fine including the methods that check
for authentication (but do not require it) untill I login, then all methods
that require or check authentication throw a nullreference exception, I've
been over it dozens of times and I'm still clueless why this is happening :/

--Authentication method on the webservice

[WebMethod]
public User SignIn(string name, string pass) {
DataRow druser = this._db.Users.GetUserByName(name);
if (druser != null) {
if (druser["Password"].Equals(pass) && (bool)druser["Activated"]) {
User user = new User();
//......setting all user properties here.
HttpContext.Current.Response.Cookies.Add(System.Web.Security.FormsAuthentication.GetAuthCookie(name,
false));
Global.Add(user);
return user;
}
}
return null;
}

--method on the webservice that checks for authentication but doesn't
required it.

[WebMethod]
public DataSet GetForumGroups()
{
long characterid = 0;
if (Context.User.Identity.IsAuthenticated)
characterid =
Global.GetUser(Context.User.Identity.Name).ActiveCharacter.ID;
DataSet ds = new DataSet();
this._db.ForumGroups.GetTable(ds, characterid);
return ds;
}


--consuming the webservice

protected User btnLogin_Click(object sender, EventArgs e)
{
WebDB.Service webdb = new WebDB.Service();
webdb.CookieContainer = this.Cookies;
User user = webdb.Login(txtName.Text, txtPass.Text);
if(user != null)
System.Web.Security.FormsAuthentication.SetAuthCookie(txtName.Text,
true);
return user;
}

private CookieContainer Cookies
{
get {
object o = Session["Cookies"];
if (o == null)
{
CookieContainer cookies = new CookieContainer();
Session.Add("Cookies", cookies);
return cookies;
}
return (CookieContainer)o;
}
set {
if (Session["Cookies"] == null)
Session.Add("Cookies", value);
else
Session["Cookies"] = value;
}
}


-- calling a method on the webservice that checks for authentication but
doesn't required it.

private DataSet GetGroups()
{
WebDB.Service webdb = new WebDB.Service();
webdb.CookieContainer = this.Cookies;
return webdb.GetForumGroups(); //<--- this works fine untill I
login, then it throws the following exception:
System.Web.Services.Protocols.SoapException: Server was unable to process
request. ---> System.NullReferenceException: Object reference not set to an
instance of an object.
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top