设置 img 基本身份验证的凭据

发布于 2024-12-03 05:29:43 字数 757 浏览 3 评论 0原文

我正在 VS2010 中开发一个内部 .Net 应用程序,以便在我公司的 Intranet 中部署。该站点使用 Windows 身份验证,以便用户在成功通过域身份验证后无需登录。对于一个页面,需要我从内网上获取一些信息,包括照片和其他信息。对于员工照片,我使用一个控件:

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

从后端,这允许我通过更改照片 url 来根据用户选择来更改显示的照片,如下所示:

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

但是路径受密码保护。有没有办法明确提供用于访问 asp:image 的凭据,以便我可以传入当前经过身份验证的用户的凭据,而不提示用户进行身份验证?

更新

曾经有一种方法可以将用户名+密码指定到 img 标签中,例如:

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

或类似的内容。这样凭证就可以访问该目录了吗?现在这有可能吗?

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 explicitly 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2024-12-10 05:29:43

我最终使用 WebClient 类设置凭据以向其他服务器进行身份验证,然后在本地下载照片:

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

之后,我引用了服务器上照片的本地副本:

imgPhoto.ImageUrl = photoPath;

这解决了我遇到的身份验证问题图像。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文