Posts

Showing posts with the label Silverlight

User authentication in SilverLight

I wanted to know how to authenticate users in a SilverLight app using their Windows login info. 01: Set the authentication mode to Windows and <deny users="?"/> in <system.web> within web.config 02: Move the silverlight control to Default.aspx and set that as your start page 03: Add the following Page_Load code protected void Page_Load(object sender, EventArgs e) { IPrincipal p = HttpContext.Current.User; if (p == null) throw new SecurityException("No current user"); if (!(p is WindowsPrincipal)) throw new SecurityException("Not a windows user"); if (!p.Identity.IsAuthenticated) throw new SecurityException("Not authenticated"); Xaml1.InitParameters = string.Format("user={0},session={1}", p.Identity.Name, Session.SessionID); } 04: In app.xaml.cs you can now read the InitParameters using e.InitParameters in the Application_Startup method.

Silverlight and webservices

First download the binaries you need from here: http://silverlight.net/GetStarted/ Next run VS2008 and create a new project. Select the Silverlight node and then the Silverlight Application node. ProjectName = MySilverlightApp Tick the checkbox "Create directory for solution" Click OK On the wizard page you want the default values: * Add a new page to the solution for hosting the control Project type = Web Site Name = MyWebService Now delete the two ASPX files, we wont be needing those. Rename the HTML page to Index.html and set it as the project start page. Right click the website project and select "Add new item". Select "Web Service". Name = DateTimeService.asmx Click ADD Change the HelloWorld method to public DateTime GetServerDateTime() {   return DateTime.Now; } Right-click the References node on the Silverlight project and select "Add service reference". Click the "Discover" button, and in the tree view that appears select the Da...