开发者

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();

        // 开发者_Go百科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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜