Skip to content

Commit ccf0307

Browse files
committed
added full support for Azure Partial Trust and enabled ASP.NET Medium Trust with a client defined permissions file.
1 parent 475c55a commit ccf0307

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

Bson/ObjectModel/ObjectId.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
using System.Collections.Generic;
1818
using System.Diagnostics;
1919
using System.Linq;
20+
using System.Runtime.CompilerServices;
21+
using System.Security;
2022
using System.Security.Cryptography;
23+
using System.Security.Permissions;
2124
using System.Text;
2225
using System.Threading;
2326

@@ -48,8 +51,18 @@ public struct ObjectId : IComparable<ObjectId>, IEquatable<ObjectId>
4851
static ObjectId()
4952
{
5053
__staticMachine = GetMachineHash();
51-
__staticPid = (short)Process.GetCurrentProcess().Id; // use low order two bytes only
5254
__staticIncrement = (new Random()).Next();
55+
56+
try
57+
{
58+
// we are testing for FullTrust here and, if we have it, then we use the current process' id.
59+
new PermissionSet(PermissionState.Unrestricted).Demand();
60+
SetPidToCurrentProcessId();
61+
}
62+
catch (SecurityException)
63+
{
64+
__staticPid = (short)0;
65+
}
5366
}
5467

5568
// constructors
@@ -364,6 +377,12 @@ private static int GetTimestampFromDateTime(DateTime timestamp)
364377
return (int)Math.Floor((BsonUtils.ToUniversalTime(timestamp) - BsonConstants.UnixEpoch).TotalSeconds);
365378
}
366379

380+
[MethodImpl(MethodImplOptions.NoInlining)]
381+
private static void SetPidToCurrentProcessId()
382+
{
383+
__staticPid = (short)Process.GetCurrentProcess().Id;
384+
}
385+
367386
// public methods
368387
/// <summary>
369388
/// Compares this ObjectId to another ObjectId.

GlobalAssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
using System.Reflection;
1717
using System.Runtime.CompilerServices;
1818
using System.Runtime.InteropServices;
19+
using System.Security;
1920

2021
[assembly: AssemblyCompany("10gen Inc.")]
2122
[assembly: AssemblyCopyright("Copyright © 2010-2012 10gen Inc.")]
2223
[assembly: AssemblyTrademark("")]
2324
[assembly: AssemblyCulture("")]
25+
[assembly: AllowPartiallyTrustedCallers]
2426

2527
// Setting ComVisible to false makes the types in this assembly not visible
2628
// to COM components. If you need to access a type in this assembly from

0 commit comments

Comments
 (0)