2009-09-03 159 views
2

所以我试图让一个简单的系统工作,其中我有一个asp.net mvc web应用程序,表单身份验证已经启动并且与创建的用户一起运行。使用mvc控制器/视图,我可以毫无问题地登录。ASP.NET MVC + Silverlight +表单身份验证

然后,我将Silverlight应用程序添加到解决方案中,使用现有的Web应用程序作为主机。我创建了一个Silverlight启用Web服务并添加以下代码的经营合同:

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

在Silverlight应用程序,我添加了两个文本框和一个按钮和一个服务参考WCF服务。在按钮单击事件,我有这样的代码:

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"); 
     } 
    } 

所以,问题是,当我输入我的登录信息,然后单击按钮,我得到的是错误框。我似乎无法得到它来验证用户。

我失去了什么?

UPDATE: 以下是错误我在异步完整的处理程序得到:

行:86 错误:未处理的错误在Silverlight应用程序 代码:4004
类别:ManagedRuntimeError
留言信息:System.NullReferenceException : 你调用的对象是空的。 在UserPortal.MainPage.client_AuthenticateCompleted(对象发件人,AuthenticateCompletedEventArgs E) 在UserPortal.AuthenticationService.AuthenticationClient.OnAuthenticateCompleted(对象状态)

更新2: 所以我上面贴的错误是因为e.Error属性一片空白。所以我没有从认证服务获得任何特定的错误。有什么我需要在web.config中更改以通过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> 
+0

你可以请尝试MessageBox.Show(e.ToString())或MessageBox.Show(e.Error.ToString())或尝试打印完整的错误,你会得到究竟是什么错误。 – 2009-09-03 06:56:27

回答

0

好吧,所以我得到它的工作,有点。

继内容here我设法让一个服务启动并运行,这将允许我成功登录。问题是我必须将RequireSSL更改为false。我无法使服务在https上运行。

任何人都知道我需要做什么才能使其在SSL上工作?我现在正在使用ASP.NET开发服务器,我需要在这个盒子上配置一个真正的IIS版本来工作吗?

+0

我做了很多#if DEBUG RequireSSL = false #else RequireSSL #endif类型的东西来解决ASP.Net开发服务器的特定缺陷 – thaBadDawg 2009-11-07 16:08:14

0

当使用WCF并在开发服务器上运行时,您需要安装正确的证书。它不是silverlight它是wcf客户端代理,它试图验证你的证书并且我认为失败。当你尝试从asp或浏览器中找到它会发生什么?