Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit Help: Silverlight Login in ASP.NET
14 replies. Latest Post by sladapter on August 13, 2009.
(0)
Silverli...
Member
138 points
42 Posts
07-03-2008 2:15 AM |
Hi! Can anyone help?
I am just to begin is the Silverlight world, so it would be helpful to me if you explain me more details and simple.
Now I am running
- Visual Studio 2008 Pro with Silverlight 2 Beta 2 installed ( SDK + Runtime)
- Expression Blend 2.5 June Preview
- ASP.NET 3.5 ( VB.NET )
and I have build a websit that has the Log in page using asp.net login control.
Now I want to have the silverlight login interface instead of asp.net control,.and working as same as in my asp.net login control.
The eaiest to say is:
ASP.NET Control
-The username ; username textbox, password, password textbox, login button, reset button, forgot password button
will be replace by
- Silverlight 2 Beta 2
Could anyone help please!!!!
Thanks
xanoxate
85 points
23 Posts
07-03-2008 5:21 AM |
Silverlight20:Could anyone help please!!!!
Brad Abrams covers this on his blog
Accessing the ASP.NET Authentication, Profile and Role Service in Silverlight
07-03-2008 8:30 AM |
Thanks for this links, but I already tried it, it doesn't work properly.
ans I need more simple way to do it.
Thanks again.
sladapter
All-Star
17445 points
3,173 Posts
07-03-2008 11:32 AM |
If you want to Silverlight interface just build a Silverlight login UserControl with all the fields you need. When user click the login button you need to send the data (loing/password) back to Server through a Web Service call to do the validation then wait the result back to do what ever you want to do accordingly.
The validation logic should be the same no matter if you choose to use HTML form control(asp.net control), AJax or Silverlight control. The only difference between using Form controls and Silverlight is with form control you usually submit the form. With Silverlight (or Ajax), you gether all the data then just send the data back through WebService call.
07-03-2008 10:16 PM |
Hi! This is really helpful. but as I said in the beginning i am really new to the programing world, so could you mind to write me the tutorial more details ablut your tip above?
Thanks in Advance
07-04-2008 11:14 AM |
Hi,
If you are totally new to programming and silverlight, you need to go through some tutorials first before you start to write this login control:
http://silverlight.net/Learn/videocat.aspx?cat=2
http://silverlight.net/learn/tutorials.aspx
Login control is a simple control. Here is what knowledge you need:
1) Build a UserControl in Silverlight with layout control like Grid/StackPanel etc and silverlight build-in control like TextBox and Button.
Currently there is no built-in password control, but for beginner you can just first use a Textbox as password control until you know how to write a custom control. There are some code for password control in this forum you can use. But that's not the most important thing for now.
2) Write WCF Service and have Silverlight consum the WCF service.
3) I assume you know how to write login validation logic
Here is a sample project I created:
http://www.2shared.com/file/3543584/648731dd/SilverlightLogin.html
DelaroAl...
8 points
4 Posts
08-06-2009 11:25 PM |
Hi, I have seen ur project in the link. But Silverlight is now version 2. No longer beta, So can u put in a updated version of the login application? As ur current Application cannot be run in silverlight 2. Will appreciate it if you can put up a updated version. Tks
08-07-2009 1:44 PM |
Get the latest from here:
http://cid-9cffd385fd75195b.skydrive.live.com/self.aspx/Silverlight/SilverlightLogin.zip
08-10-2009 11:23 PM |
Hi, I saw the application and it was great!
But i got a few questions, i apologise if they seem dumb coz i'm just a beginner programmer. Sry
1: Where do u create the User? Is it in the ASP.NET? or can u create users in the database and read from there?
2: If the login is successfull, Ur FirstPage displayed an error abt the html
// throw new Error(errMsg);
Tks for ur reply! looking forward to it.
08-11-2009 9:40 AM |
You have to write the real validation code yourself. The user info usually is stored in database. But it dose not matter where they are, all the validation code are running on server side. The validation code should have nothing to do if you are using Silverlight as login GUI or you are using normal ASP page as your login GUI.
With Silverlight you just need to pass the login/password info from Silverlight back to server via a Web service then get the validation result back.The demo code only shows you how to do this part.
08-11-2009 10:50 PM |
I tried follow the blog in the 2nd post above, but seems to have alot of problems. I created a Text file called: "AuthenticationService.svc" with content: <%@ ServiceHost Language="C#" Service="System.Web.ApplicationServices.AuthenticationService" %>
Then i added the following lines to YOUR application but it didnt work. Can u pls Suggest a Solution?
"web.config"
<system.serviceModel> <services> <!-- this enables the WCF AuthenticationService endpoint --> <service name="System.Web.ApplicationServices.AuthenticationService" behaviorConfiguration="AuthenticationServiceTypeBehaviors"> <endpoint contract="System.Web.ApplicationServices.AuthenticationService" binding="basicHttpBinding" bindingConfiguration="userHttp" bindingNamespace="http://asp.net/ApplicationServices/v200"/> </service> </services> <bindings> <basicHttpBinding> <binding name="userHttp"> <!-- this is for demo only. Https/Transport security is recommended --> <security mode="None"/> </binding> </basicHttpBinding> </bindings> <behaviors> <serviceBehaviors> <behavior name="AuthenticationServiceTypeBehaviors"> <serviceMetadata httpGetEnabled="true"/> </behavior> </serviceBehaviors> </behaviors> <!-- this is needed since this service is only supported with HTTP protocol --> <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> </system.serviceModel>
<authentication mode="Forms" />
<system.web.extensions> <scripting> <webServices> <authenticationService enabled="true" requireSSL="false"/> </webServices> </scripting> </system.web.extensions>
The Error that i got is:
Warning 1 C:\Documents and Settings\072502U\My Documents\Silverlight APPLICATION\SilverlightLogin\LoginSilverlightWeb\AuthenticationService.svc: ASP.NET runtime error: Sections must only appear once per config file. See the help topic <location> for exceptions. (C:\Documents and Settings\072502U\My Documents\Silverlight APPLICATION\SilverlightLogin\LoginSilverlightWeb\web.config line 148) C:\Documents and Settings\072502U\My Documents\Silverlight APPLICATION\SilverlightLogin\LoginSilverlightWeb\AuthenticationService.svc 1 1 LoginSilverlightWebHow do i fix it? tks alot.DelaroAlexandra
08-12-2009 9:58 AM |
DelaroAlexandra:Then i added the following lines to YOUR application but it didnt work. Can u pls Suggest a Solution?
Why do you want to add some thing that from other people's blogs to my application and expected it to work automatically? My demo should just work without changing anything. I'm not using System.Web.ApplicationServices.AuthenticationService.
You need to understand what is going on in the demo. Then you can just change the code to do the real authentication in the DoLogin function in the Login.svc.cs. This is more generic and flexible way of doing login validation, assuming your user information is stored in DB or some other places other than the ASP.NET web site.
public LoginInfo DoLogin(string login, string password)
{
//Put your real authentication code here, connect your DB, do the validation etc.
}
You can also follow Brad Abream's blogs. That one was using System.Web.ApplicationServices.AuthenticationService which assuming the Login info is configured in the ASP.NET web site.
You can get some good idea on how to do things differently by trying different sample code. But no matter which method you chose, you need to understand them first before you mixing them together.
Christin...
2 points
1 Posts
08-12-2009 10:18 PM |
Hi sladapter, can give an example of authentication in your code:
How do you login using ur demo if I am using ASP.NET login?
Can we get user login info from the sql database and login?
tyvm in advance!!
08-13-2009 9:05 AM |
If you want to use ASP.NET login, just follow the instruction in Brad Abream's blogs. That user info is also stored in a SQL database. But you just have to follow the specific setup mentioned in the blog.
If you do not want use ASP.NET login, assume your user info is stored in a database (it can be any database, does not have to be a SQL server). All you have to do is to query a User who matchs the login and password. If you found one, then the login pass, if not, login failed. This would be the simplest logic for login. In real case, it's more complicated than just verify login/password. You need to compare encripted password, you need to find the User Roles or Groups if you set the user that way. You need to find what kind of function right the user has, etc. Then stored all these info to a Token or something. pass it back to client. You can write the token to cookie so you do not have to do this on the following request within a login session.
I assume you already know how to write .NET code to connect to DB and query data from database. If not, you need to learn that. There are tons of online tutorials which are really easy to follow. You can start from here: http://silverlight.net/GetStarted/