Skip to content

Commit 4fd1e52

Browse files
Fix SecurityException on restricted environments
1 parent 3aeb601 commit 4fd1e52

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Cloudinary/Api.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ public Api(Account account) : base(account)
6464
/// </summary>
6565
static Api()
6666
{
67-
var version = Assembly.GetExecutingAssembly().GetName().Version;
68-
var frameworkDisplayName = Assembly.GetExecutingAssembly().GetCustomAttributes(true).
69-
OfType<System.Runtime.Versioning.TargetFrameworkAttribute>().First().FrameworkDisplayName;
67+
var version = new AssemblyName(typeof(Api).Assembly.FullName).Version;
7068

71-
USER_AGENT = String.Format("CloudinaryDotNet/{0}.{1}.{2} ({3})",
72-
version.Major, version.Minor, version.Build, frameworkDisplayName);
69+
USER_AGENT = $"CloudinaryDotNet/{version.Major}.{version.Minor}.{version.Build} (.NET Framework 4)";
7370
}
7471

7572
public override T CallAndParse<T>(HttpMethod method, string url, SortedDictionary<string, object> parameters, FileDescription file,
@@ -81,10 +78,10 @@ public override T CallAndParse<T>(HttpMethod method, string url, SortedDictionar
8178
file,
8279
extraHeaders))
8380
{
84-
81+
8582
return Parse<T>(response);
8683
}
87-
84+
8885
}
8986

9087
/// <summary>
@@ -106,7 +103,7 @@ public HttpWebResponse Call(HttpMethod method, string url, SortedDictionary<stri
106103
}
107104

108105
PrepareRequestBody(request, method, parameters, file, extraHeaders);
109-
106+
110107
try
111108
{
112109
response = (HttpWebResponse)request.GetResponse();
@@ -185,7 +182,7 @@ private void PrepareRequestContent(ref HttpWebRequest request, SortedDictionary<
185182
private void PrepareMultipartFormDataContent(HttpWebRequest request, SortedDictionary<string, object> parameters, FileDescription file)
186183
{
187184
request.ContentType = "multipart/form-data; boundary=" + HTTP_BOUNDARY;
188-
185+
189186
using (Stream requestStream = request.GetRequestStream())
190187
{
191188
using (StreamWriter writer = new StreamWriter(requestStream))
@@ -258,7 +255,7 @@ protected override string EncodeApiUrl(string value)
258255
{
259256
return HttpUtility.HtmlEncode(value);
260257
}
261-
258+
262259
private static void SetHttpMethod(HttpMethod method, HttpWebRequest req)
263260
{
264261
req.Method = Enum.GetName(typeof(HttpMethod), method);

0 commit comments

Comments
 (0)