Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Azure

Securing Your SharePoint and Windows Azure Solutions : Create a Windows Forms Application to Display the Shared Access Permissions Signature

11/20/2012 6:14:54 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

Create a Windows Forms Application to Display the Shared Access Permissions Signature

  1. Open Microsoft Visual Studio 2010 and create a blank solution.

  2. Right-click the solution and select Add | New Project.

  3. Select Windows Forms Application, provide a name for the application (such as BLOBUriGenerator), and click OK.

  4. Right-click the project and select Add References. Add Microsoft.WindowsAzure.StorageClient.dll (from C:\Program Files\Windows Azure SDK\v1.3\bin).

  5. Click View | Toolbox, drag two buttons onto the Windows Forms designer surface, and then drag a textbox control onto the designer surface. Your Windows Forms UI should look similar to the graphic shown here. Name the buttons btnGetData and btnExit. Name the textbox control txtbxURI.

    image with no caption
  6. Right-click the Form1.cs in the Solution Explorer and select View Code.

  7. In the code-behind, amend the code by using the bolded code shown here:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.WindowsAzure.StorageClient;
    using Microsoft.WindowsAzure;
    
    namespace BLOBUrlGenerator
    {
        public partial class Form1 : Form
        {
    
            CloudBlobContainer azureBlobContainer = null;
            CloudStorageAccount azureStorageAcct = null;
            CloudBlobClient azureBlobClient = null;
            BlobContainerPermissions azureBlobPermissions = null;
            CloudBlob azureBlob = null;
            string submissionDateTime = "";
    
            public Form1()
            {
                InitializeComponent();
                InitializeStorage();
            }
    
            private void InitializeStorage()
            {
                var accountInfo = "DefaultEndpointsProtocol=http;Accountname=fabrikaminc;
    AccountKey=<your account key here>
    
                azureStorageAcct = CloudStorageAccount.Parse(accountInfo);
    
                azureBlobClient = azureStorageAcct.CreateCloudBlobClient();
    
                azureBlobContainer = azureBlobClient.GetContainerReference(
                   "c10testcontainer");
                azureBlobContainer.CreateIfNotExist();
                azureBlob = azureBlobContainer.GetBlobReference("c10testblob");
                azureBlob.UploadText("Test Text");
            }
    
            private void btnGetURI_Click(object sender, EventArgs e)
            {
                SharedAccessPolicy tempAccess = new SharedAccessPolicy();
                tempAccess.SharedAccessStartTime = DateTime.Now;
                tempAccess.SharedAccessExpiryTime = DateTime.Now.AddHours(48);
                tempAccess.Permissions = SharedAccessPermissions.Read;
    
                BlobContainerPermissions tempPermissions = new BlobContainerPermissions();
                tempPermissions.SharedAccessPolicies.Clear();
                tempPermissions.SharedAccessPolicies.Add("John Doe", tempAccess);
                azureBlobContainer.SetPermissions(tempPermissions);
    
                string sharedAccessSig = azureBlobContainer.
                   GetSharedAccessSignature(tempAccess);
                string sharedAccessURI = azureBlobContainer.Uri.AbsoluteUri +
                   sharedAccessSig;
    
                txtbxURI.Text = sharedAccessURI;
            }
    
            private void btnExit_Click(object sender, EventArgs e)
            {
                Application.Exit();
            }
        }
    }

    The preceding code uses the Microsoft.WindowsAzure.StorageClient library to programmatically interact with a Windows Azure BLOB storage account. You’ll note that there are several class-level declarations in the snippet, which represent the different storage objects that you need when interacting with Windows Azure BLOB storage. Then, as was discussed earlier in this section, you use the SharedAccessPolicy class to create a temporary shared access permissions signature, which can be used to download data and information from the BLOB. The shared access permissions URI that is created (sharedAccessURI) is then displayed in the textbox property.

  8. After you finish adding the code, press F5 to debug the application. You should see something similar to the following—which exposes the shared access permissions signature in the form of a URI.

    image with no caption

Though this application is fairly simple, it illustrates how you can create controlled access to BLOB storage resources. This code within the simple Windows Forms code can equally apply to SharePoint Web Parts (or other SharePoint artifacts) and Silverlight applications that can be hosted in SharePoint.

Note

Although Windows Azure storage provides shared access permissions, the use of shared access permissions is less apparent with the other parts of the platform. The Windows Azure AppFabric platform, for example, employs a different type of security called the Access Control Service, which uses claims to authenticate users and applications.

Other -----------------
- Securing Your SharePoint and Windows Azure Solutions : Configuring BCS Security - Create an Application ID, Assess Permissions on the ECT
- Deploying to Windows Azure : Changing live configuration, Upgrading the deployment, Running the deployment
- Deploying to Windows Azure : Preparation application for deployment, Ready for deployment
- Setting up hosted service in Windows Azure
- Azure Monitoring and Diagnostics : Logging config data in our application, Transferring and persisting diagnostic data
- Azure Monitoring and Diagnostics : Azure Diagnostics­ under the hood, Enabling diagnostic logging
- Web Services and Azure : Our WCF web services
- Web Services and Azure : Creating a new WCF service web role
- Azure Blob Storage : Windows Azure Content Delivery Network, Blob Storage Data Model
- Azure Blob Storage : Blobs in the Azure ecosystem, Creating Blob Storage
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server