providing domain/user credentials to webview control

和自甴很熟 提交于 2019-11-30 22:22:20

In order to connect to sites on your corporate network you must enable the privateNetworkClientServer capability in your Package.appxmanifest. You can do this in the XML or you can double-click on the file in Visual Studio and use the designer (capabilities tab). In the UI it's called "Home or Work Networking".

Now that you have access to the intranet you can navigate to the site but you will be prompted to provide credentials. If you want the users domain identity to automatically be supplied (enterprise single sign on) you need to enable the enterpriseAuthentication capability as well. This is called "Enterprise Authentication" in the manifest UI.

From there you should be able to browse to any intranet site using a WebView and not have to authenticate. If you are looking to do things outside of the WebView, you should check out the following articles and samples:

Using WebAuthenticationBroker:

http://code.msdn.microsoft.com/windowsapps/Web-Authentication-d0485122

WebAuthenticationBroker has an option called UseCorporateNetwork. Make sure to use that when following along in the sample above.

Finally, if you want to do Single Sign On with other sites like Facebook or Flicr, see this sample:

http://msdn.microsoft.com/en-US/library/windows/apps/xaml/Hh465283

I have came across same problem, but luckily found an answer :) Main problem in here is that Windows store applications contain 2 diffrent HttpClient's

One of them is "classic" one we know from c# apps (used automatically) and the other one is "new" HttpClient - which is connected with WebView :)

Bellow are both types : System.Net.Http.HttpClient ( classic one ) Windows.Web.Http.HttpClient ( new one )

So remember to declare the new One and do something like the code bellow

var filter = new HttpBaseProtocolFilter();    
filter.ServerCredential = new Windows.Security.Credentials.PasswordCredential("http://website","login", "password");
            Windows.Web.Http.HttpClient client2 = new Windows.Web.Http.HttpClient(filter);
            var response = await client2.GetAsync(new Uri("http://website"));
 WebView.Source = new Uri("http://website");

Now remember to change login and password to credentials you want to use, and a website is a site you want to authenticate to.

It is important to get the response from server - this will make user authenticated @ server so next time you go with webView to that site you will be authenticated

It works fine with basic authentication and NTLM authentication

In this cae scenario remember to have enterpriseAuthentication turned off

Hope it will help people searching for solution of this problem :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!