ASP.NET MVC + Silverlight + Forms Authentication

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

Then I added a silverlight app to the solution using my existing web app as the host. I created a silverlight enabled web service and added a working 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 application, I added two text boxes and a button and a link 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 that when I enter my login information and click the button, all I get is an error box. I can't get it to authenticate the user.

What am I missing?

UPDATE: Here is the error I am getting in the async handler:

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

UPDATE 2: So the error I mentioned above is that 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 make this work through 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>

      

+2


source to share


2 answers


Ok, so I got it to work, sort of.

After the content here, I was able to start and start a service that would allow me to successfully login. The problem is, I had to change RequireSSL to false. I couldn't get the service to work on https.



Does anyone know what I need to do to get it to work on SSL? I am using ASP.NET development server right now, do I need to configure the real version of IIS in this box to work?

0


source


When using WCF and running on a development server, you need to install the appropriate certificates. its not silverlight its a wcf client proxy trying to verify your truth and i don't think so. What happens when you try to hit it from asp or browser?



0


source







All Articles