1

While I was working on my localhost it worked flawlessly.

However, when I deployed the application to another server it started to raise an exception.

Basically, this is the instruction that causes the Exception:

HttpContext.Current.User.IsInRole(*roleName*)

where roleName is a string representing the different roles in the application.

Exception fired:

System.Web.HttpUnhandledException

Update: This is how the user is being authenticated.

protected void LoginControl_Authenticate(object sender, AuthenticateEventArgs e)
{
    Page.Validate();
    if (!Page.IsValid) return;

    if (MyAuthenticate(LoginControl.UserName, LoginControl.Password))
    {
        if (LoginControl.RememberMeSet == true)
        {
            createCookie(LoginControl.UserName, Convert.ToInt32(ViewState["idcustomer"]), true);
        }
        else
        {
            createCookie(LoginControl.UserName, Convert.ToInt32(ViewState["idcustomer"]), false);
        }
        e.Authenticated = true;
        Response.Redirect(FormsAuthentication.GetRedirectUrl(LoginControl.UserName, true));
    }
    else
    {
        e.Authenticated = false;
    }

If it is related to the user authentication, what am I missing? Thanks in advance.

UPDATE: Thanks to all. I have just done a Remote Debugging and realize this is the actual error:

enter image description here

Now, this is the situation: the User was authenticated in the login page. So, I think it is not a problem with the connection to the DB. Otherwise, the User wouldn't have been able to pass the login page to the MasterPage (where this error is being raised).

What can I be missing? Thanks again,

aleafonso
  • 2,244
  • 8
  • 38
  • 58

2 Answers2

0

Wild stab in the dark but the inner exception is probably a null reference exception being caused by the fact the user is not authenticated on the server so HttpContext.Current.User is null. I would bet it is just that windows integrated authentication is not enabled on the live web server or a similar authentication setup issue.

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
  • OK from your code i see you are using forms authentication, is forms authentication supported/enabled on your server? What happens when you try to log in? – Ben Robinson Nov 16 '11 at 14:09
  • Ok. How can I check whether it is supported/enabled in the server? – aleafonso Nov 16 '11 at 14:12
  • That authentication in the login page is done successfully. The problem is when loading the master page and asks for: HttpContext.Current.User.IsInRole(roleName) – aleafonso Nov 16 '11 at 14:13
  • I have just followed this post to enable Forms Authentication in the server: http://technet.microsoft.com/en-us/library/cc771077(WS.10).aspx, but I keep getting the same error – aleafonso Nov 16 '11 at 14:58
  • 1
    I made a wild guess that HttpContext.Current.User is null and that you are getting a null ref exception, why don't you try confirming/refuting those things first. – Ben Robinson Nov 16 '11 at 14:59
  • You're right, there is a problem with the User. Please, have a look at the Update in the question – aleafonso Nov 16 '11 at 15:17
0

The solution for this problem was to create the mysql_aspnet_membership provider by granting full trust through the machine.config and autogenerating the schema, instead of manually creating the membership tables in the database, which I though there could have been a valid way to create the db.

Afterwards, this didn't break anymore.

aleafonso
  • 2,244
  • 8
  • 38
  • 58