简体   繁体   中英

Silverlight Business Application Windows Authentication

I cannot seem to get Windows Authentication to work in the Silverlight Business Application.

I have made the changes required see below

Changed to Windows authentication in App.xaml

    public App()
    {
        InitializeComponent();

        // Create a WebContext and add it to the ApplicationLifetimeObjects
        // collection.  This will then be available as WebContext.Current.
        WebContext webContext = new WebContext();
        //webContext.Authentication = new FormsAuthentication();
        webContext.Authentication = new WindowsAuthentication();
        this.ApplicationLifetimeObjects.Add(webContext);
    }

Changed to Windows authentication in web.config

<authentication mode="Windows"/>

<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"/>

I put a breakpoint on the Application_UserLoaded event but nothing happens:-

    private void Application_UserLoaded(LoadUserOperation operation)
    {
        foreach (var r in WebContext.Current.User.Roles)
        {
            //do something
        }
    }

Can anyone suggest what is going wrong. I have made no other changes to the project at all.

You must have this line in the Application_Startup :

WebContext.Current.Authentication.LoadUser(this.Application_UserLoaded, null);

This will automatically authenticate a user when using Windows authentication.

This happened to me previously as well. It turned out that Silverlight debugging wasn't enabled in the properties of the Web project. Right click on the.Web project and click on properties. Next click on the Web tab and on the bottom ensure the Silverlight checkbox is checked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM