开发者

Setting credentials for img basic authentication

I am developing a internal .Net application in VS2010 for deployment within my company's intranet. The site uses Windows Authentication so that users do not have to log in when they are successfully authenticated to the domain. For one page, it is required that I get some information from the intranet including photos and other information. For the employee photo, I am using a control:

<asp:Image ID="imgPhoto" Style="display: inline-block" runat="server" CssClass="EmployeePhoto"
                alt="Photo not available" />

From the back end, this allows me to change which photo is displayed depending on user choices by changing the photo url as follows:

imgPhoto.ImageUrl = string.Format("http://{0}/{1}.jpg", MySitePath, employeePhotoPath);

The path is password protected however.Is there any way to explicitl开发者_如何学JAVAy provide the credentials used to access the asp:image so that I can pass in the credentials of the current authenticated user without the user being prompted to authenticate?

UPDATE

There used to be a way to specify the username + password into the img tag like:

<img src="http://username:password@server/photos/1.jpg"> 

or something similar. So that the credentials are available to access the directory? Is this possible in any way now?


See: http://www.1stbyte.com/2008/03/15/automatic-windows-authentication-with-firefox-networkautomatic-ntlm-authtrusted-uris/

or, if you want an addon to manage that: https://addons.mozilla.org/en-US/firefox/addon/integrated-auth-for-firefox/


I ended up using the WebClient class to set the credentials to authenticate to the other server and then download the photo locally:

                WebClient myWC = new WebClient();                    
                myWC.Credentials = new System.Net.NetworkCredential(bioSearchUsername, bioSearchPassword);
                string photoPath = Server.MapPath("~/images/Employees/" + employee + ".jpg");
                myWC.DownloadFile(imageLocation, photoPath);

After that, I referenced the local copy of the photo on the server:

imgPhoto.ImageUrl = photoPath;

This got around the authentication problems I was running into with the image.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜