发布后未加载SharePoint上的图像 [英] Images on SharePoint not loading after publish

查看:69
本文介绍了发布后未加载SharePoint上的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要从SharePoint中检索用户个人资料图片,然后在页面上显示这些用户,并将img元素中的src属性设置为图像的URL.

I am retrieving user profile pictures from SharePoint then displaying those users on a page, settings the src attribute in img element to the url of the image.

在VS中进行调试时,它可以完美地工作.

It works perfectly when debugging in VS.

但是,在发布到Azure之后,图像没有加载.奇怪的是,当我单击图像的链接后,它似乎已对我进行身份验证,然后图像才开始加载...

However, after I publish to Azure, the images are not loading. What is strange is that after I click on the link for the image, it seems to authenticate me, and then the images DO start loading...

如何仅自动传递当前用户的凭据,这样我的用户就不必导航到图像本身,而是可以在Web应用程序中看到它们?

How can I just pass in the current users credentials automatically so my users don't have to navigate to the image itself before seeing them in the web app?

元素示例:

<img src="https://companyname-my.sharepoint.com:443/User%20Photos/Profile%20Pictures/firstname_lastname_company_com_MThumb.jpg?t=63655312814" class="userPic">

显然,当前登录的用户是受信任的,因为它可以在访问该URL后正常工作-我不能在该地址中添加某种形式的参数以自动执行该操作吗?

The currently signed in user is obviously trusted, as it does work after going to that url - can't I add a paramater of some kind to that address to do it automatically?

真的很感谢您的帮助.

推荐答案

使用Azure存储,如果图像已保存为私有图像,则需要共享访问签名.

With Azure storage, if an image has been saved as private then it will require a sharedaccesssignature.

对于我在自己网站上拥有的任何图片,我都有一个类似以下的类:

For any images i have for my own sites i have a class like the below:

public string GetAzureStoreImage(string fileName, string containerName)
{
        string imageUrl = string.Empty;

        // Connect to cloud storage account
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("YourStoredConnectionString"));

        // Connect blob client
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

        // Connect to container
        CloudBlobContainer container = blobClient.GetContainerReference(containerName);

        // Get reference for current file
        CloudBlockBlob blob = container.GetBlockBlobReference(fileName);

        if (blob.Exists())
        {
            // Create access token for file share
            var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
            {
                Permissions = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10),
            }, new SharedAccessBlobHeaders()
            {
                ContentDisposition = "attachment; filename=" + fileName
            });

            // Collect url and download file
            imageUrl = string.Format("{0}{1}", blob.Uri, sasToken);
        }

        return imageUrl;
}

您将需要为其包含Microsoft.WindowsAzure.Storage和Microsoft.WindowsAzure.Storage.Blob引用,但这将提供一个10分钟的临时令牌来访问文件,然后该文件将允许返回的"imageurl"您的图片来源.

You will need to include the Microsoft.WindowsAzure.Storage and Microsoft.WindowsAzure.Storage.Blob references for them, but this will give a temporary 10 minute token to access the file that will then allow the returned "imageurl" to be your images source.

最后,fileName只是您要从Azure存储中收集的文件名,containerName是存储当前文件的存储桶".

Finally the fileName is just the filename you would like to collect from your Azure storage, and the containerName is what "bucket" houses the current file.

如果当前用户都有自己的安全令牌来访问应附加到您的连接字符串中的图像,则可能还需要根据当前用户信息传递另一个参数.

You may also need to pass in another parameter based on the current users information if they all have their own security tokens to access images which should be appended to your connection string.

这篇关于发布后未加载SharePoint上的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆