Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

So i am trying to get a simple system working where i have an asp.net mvc web app with the forms authentication already up and running with a user created. i can login with no problem using the mvc controller/view.

I then added a silverlight app to the solution, using the existing web app as the host. I created a silverlight-enabled web service and added an operation contract with the following code:

    [OperationContract]
    public bool Authenticate(string username, string password)
    {
        if (FormsAuthentication.Authenticate(username, password))
        {
            FormsAuthentication.SetAuthCookie(username, false);
            return true;
        }
        return false;
    }

In the silverlight app, i added two text boxes and a button, and a service reference to the WCF service. In the button click event, i have this code:

    void login_Click(object sender, RoutedEventArgs e)
    {
        AuthenticationService.AuthenticationClient client = new AuthenticationClient();
        client.AuthenticateCompleted += new EventHandler<AuthenticateCompletedEventArgs>(client_AuthenticateCompleted);
        client.AuthenticateAsync(username.Text, password.Text);
    }

    void client_AuthenticateCompleted(object sender, AuthenticateCompletedEventArgs e)
    {
        if (e.Result)
        {
            MessageBox.Show("Success");

        }
        else
        {
            MessageBox.Show("Error");
        }
    }

So the problem is, when i enter my login info and click the button, all i get is the error box. I can't seem to get it to authenticate the user.

What am i missing?

UPDATE: Here is the error i get in the async complete handler:

Line: 86 Error: Unhandled Error in Silverlight Application Code: 4004
Category: ManagedRuntimeError
Message: System.NullReferenceException: Object reference not set to an instance of an object. at UserPortal.MainPage.client_AuthenticateCompleted(Object sender, AuthenticateCompletedEventArgs e) at UserPortal.AuthenticationService.AuthenticationClient.OnAuthenticateCompleted(Object state)

UPDATE 2: So the error i posted above is because the e.Error property is null. So i am not getting any specific error from the authentication service. Is there something i need to change in the web.config to get this to work via silverlight?

	<authentication mode="Forms">
  <!-- forms loginUrl="~/Account/LogOn" timeout="2880"/ -->
	</authentication>
	<membership>
		<providers>
			<clear/>
			<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="/"/>
		</providers>
	</membership>
	<profile>
		<providers>
			<clear/>
			<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ApplicationServices" applicationName="/"/>
		</providers>
	</profile>
	<roleManager enabled="false">
		<providers>
			<clear/>
			<add connectionStringName="ApplicationServices" applicationName="/" name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
			<add applicationName="/" name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
		</providers>
	</roleManager>
share|improve this question
    
Can you please try MessageBox.Show(e.ToString()) or MessageBox.Show(e.Error.ToString()) or try to print full error and you will get what exactly the error is. –  Akash Kava Sep 3 '09 at 6:56

2 Answers 2

up vote 0 down vote accepted

Ok, so i got it to work, kinda.

Following the content here i managed to get a service up and running that would allow me to successfully login. The problem is i had to change the RequireSSL to false. I could not get the service to work running on https.

Anyone know what i need to do to get it to work on SSL? i am using the ASP.NET development server right now, do i need to configure a real version of IIS on this box for that to work?

share|improve this answer
    
I do a lot of #if DEBUG RequireSSL = false #else RequireSSL #endif type stuff to get around that particular deficiency of the ASP.Net development server –  thaBadDawg Nov 7 '09 at 16:08

When using WCF and running on an development server, you need to have proper certificates installed. its not silverlight its the wcf client proxy that tries to verify your vertificate and fail I think. What happens when you try to hit it from asp or the browser?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.