Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@ public void Insert(string key, object value, CacheDependency? dependencies, Date

internal ObjectCache ObjectCache => _cache;

public IEnumerator GetEnumerator() => ((IEnumerable)_cache).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_cache).GetEnumerator();
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public void SetCacheDependencyChanged(Action<object, EventArgs> dependencyChange
#region "IDisposable"
protected virtual void DependencyDispose() { }

protected virtual void Dispose(bool disposing)
[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1063:Implement IDisposable Correctly", Justification = Constants.ApiFromAspNet)]
internal void Dispose(bool disposing)
{
if (disposing)
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplication))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationState))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationStateBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationStateWrapper))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilities))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilitiesBase))]
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpBrowserCapabilitiesWrapper))]
Expand Down
109 changes: 109 additions & 0 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpApplicationStateBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;

namespace System.Web;

[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)]
[SuppressMessage("Naming", "CA1710:Identifiers should have correct suffix", Justification = Constants.ApiFromAspNet)]
public abstract class HttpApplicationStateBase : NameObjectCollectionBase, ICollection
{
[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
[SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = Constants.ApiFromAspNet)]
public virtual string?[]? AllKeys => throw new NotImplementedException();

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
public virtual HttpApplicationStateBase Contents => throw new NotImplementedException();

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
public override int Count => throw new NotImplementedException();

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
public virtual bool IsSynchronized => throw new NotImplementedException();

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
public virtual object SyncRoot => throw new NotImplementedException();

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
[DisallowNull]
public virtual object? this[int index] => throw new NotImplementedException();

[SuppressMessage("Design", "CA1065:Do not raise exceptions in unexpected locations", Justification = Constants.ApiFromAspNet)]
[DisallowNull]
public virtual object? this[string name]
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}

public virtual void Add(string name, object value)
{
throw new NotImplementedException();
}

public virtual void Clear()
{
throw new NotImplementedException();
}

public virtual void CopyTo(Array array, int index)
{
throw new NotImplementedException();
}

[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)]
public virtual object? Get(int index)
{
throw new NotImplementedException();
}

[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)]
public virtual object? Get(string name)
{
throw new NotImplementedException();
}

public override IEnumerator GetEnumerator()
{
throw new NotImplementedException();
}

public virtual string? GetKey(int index)
{
throw new NotImplementedException();
}

public virtual void Lock()
{
throw new NotImplementedException();
}

public virtual void Remove(string name)
{
throw new NotImplementedException();
}

public virtual void RemoveAll()
{
throw new NotImplementedException();
}

public virtual void RemoveAt(int index)
{
throw new NotImplementedException();
}

[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)]
public virtual void Set(string name, object value)
{
throw new NotImplementedException();
}

public virtual void UnLock()
{
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics.CodeAnalysis;

namespace System.Web;

[SuppressMessage("Design", "CA1010:Generic interface should also be implemented", Justification = Constants.ApiFromAspNet)]
public class HttpApplicationStateWrapper : HttpApplicationStateBase
{
private readonly HttpApplicationState _application;

public HttpApplicationStateWrapper(HttpApplicationState httpApplicationState)
{
ArgumentNullException.ThrowIfNull(httpApplicationState);

_application = httpApplicationState;
}

public override string?[]? AllKeys => _application.AllKeys;

public override HttpApplicationStateBase Contents => this;

public override int Count => _application.Count;

public override bool IsSynchronized => ((ICollection)_application).IsSynchronized;

public override NameObjectCollectionBase.KeysCollection Keys => _application.Keys;

public override object SyncRoot => ((ICollection)_application).SyncRoot;

[DisallowNull]
public override object? this[int index] => _application[index]!;

[DisallowNull]
public override object? this[string name]
{
get => _application[name];
set => _application[name] = value;
}

public override void Add(string name, object value)
{
_application.Add(name, value);
}

public override void Clear()
{
_application.Clear();
}

public override void CopyTo(Array array, int index)
{
((ICollection)_application).CopyTo(array, index);
}

public override object? Get(int index)
{
return _application.Get(index);
}

public override object? Get(string name)
{
return _application.Get(name);
}

public override IEnumerator GetEnumerator()
{
return _application.GetEnumerator();
}

public override string? GetKey(int index)
{
return _application.GetKey(index);
}

public override void Lock()
{
_application.Lock();
}

public override void Remove(string name)
{
_application.Remove(name);
}

public override void RemoveAll()
{
_application.RemoveAll();
}

public override void RemoveAt(int index)
{
_application.RemoveAt(index);
}

public override void Set(string name, object value)
{
_application.Set(name, value);
}

public override void UnLock()
{
_application.UnLock();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ public class HttpCachePolicyBase

public virtual void SetCacheability(HttpCacheability cacheability) => throw new NotImplementedException();

public virtual void SetCacheability(HttpCacheability cacheability, string field) => throw new NotImplementedException();

[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date",
Justification = "Matches HttpCachePolicy class")]
[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've removed the SetCacheability overload here... Was that intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes - it wasn't implemented on HttpCachePolicy itself so we couldn't forward it in the wrapper correctly. Happy to take a fix that implements it on all three as a follow up :) I've added tests to validate that the three (i.e. HttpContext/HttpContextBase/HttpContextWrapper) are all kept in sync when adding APIs and this case was causing failure

public virtual void SetLastModified(DateTime date) => throw new NotImplementedException();

public virtual void SetMaxAge(TimeSpan delta) => throw new NotImplementedException();

[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Date",
Justification = "Matches HttpCachePolicy class")]

[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)]
public virtual void SetExpires(DateTime date) => throw new NotImplementedException();

[SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = Constants.ApiFromAspNet)]
public virtual void SetOmitVaryStar(bool omit) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public HttpCachePolicyWrapper(HttpCachePolicy httpCachePolicy)
{
if (httpCachePolicy == null)
{
ArgumentNullException.ThrowIfNull(httpCachePolicy);
ArgumentNullException.ThrowIfNull(httpCachePolicy);
}
_httpCachePolicy = httpCachePolicy;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected HttpContextBase()

public virtual HttpApplication ApplicationInstance => throw new NotImplementedException();

public virtual HttpApplicationState Application => throw new NotImplementedException();
public virtual HttpApplicationStateBase Application => throw new NotImplementedException();

public virtual bool IsPostNotification => throw new NotImplementedException();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public HttpContextWrapper(HttpContext httpContext)

public override HttpApplication ApplicationInstance => _context.ApplicationInstance;

public override HttpApplicationState Application => _context.Application;
public override HttpApplicationStateBase Application => new HttpApplicationStateWrapper(_context.Application);

public override RequestNotification CurrentNotification => _context.CurrentNotification;

Expand Down
43 changes: 13 additions & 30 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpException.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Net;
using System.IO;
using Microsoft.AspNetCore.Http;

namespace System.Web;

public class HttpException : SystemException
{
private readonly int _httpStatusCode = 500;
private readonly int _httpStatusCode;

public HttpException()
{
Expand All @@ -17,50 +18,32 @@ public HttpException(string message) : base(message)
{
}

public HttpException(string message, Exception innerException)
public HttpException(String message, Exception innerException)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit-pick but this change seems unnecessary. We use string everywhere else in this file.

: base(message, innerException)
{
}

public HttpException(int httpStatusCode)
{
_httpStatusCode = httpStatusCode;
}

public HttpException(HttpStatusCode httpStatusCode)
{
_httpStatusCode = (int)httpStatusCode;
}

public HttpException(int httpStatusCode, string message)
: base(message)
{
_httpStatusCode = httpStatusCode;
}

public HttpException(HttpStatusCode httpStatusCode, string message)
: base(message)
{
_httpStatusCode = (int)httpStatusCode;
}

public HttpException(int httpStatusCode, string message, Exception innerException)
: base(message, innerException)
{
_httpStatusCode = httpStatusCode;
}

public HttpException(HttpStatusCode httpStatusCode, string message, Exception innerException)
: base(message, innerException)
{
_httpStatusCode = (int)httpStatusCode;
}

[Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1024:Use properties where appropriate", Justification = Constants.ApiFromAspNet)]
public int GetHttpCode()
{
return StatusCode;
}
public int GetHttpCode() => GetHttpCodeForException(this);

public int StatusCode => _httpStatusCode;
internal static int GetHttpCodeForException(Exception e) => e switch
{
HttpException { _httpStatusCode: { } code } when code > 0 => code,
UnauthorizedAccessException => StatusCodes.Status401Unauthorized,
PathTooLongException => StatusCodes.Status414UriTooLong,
{ InnerException: { } inner } => GetHttpCodeForException(inner),
_ => 500
};
}
4 changes: 1 addition & 3 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ public bool IsLocal

public int TotalBytes => (int)InputStream.Length;

public bool IsAuthenticated => LogonUserIdentity?.IsAuthenticated ?? false;

public IIdentity? LogonUserIdentity => Request.HttpContext.User.Identity;
public bool IsAuthenticated => Request.HttpContext.User is { Identity.IsAuthenticated: true };

public Encoding? ContentEncoding => TypedHeaders.ContentType?.Encoding;

Expand Down
2 changes: 0 additions & 2 deletions src/Microsoft.AspNetCore.SystemWebAdapters/HttpRequestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public virtual string? ContentType

public virtual bool IsAuthenticated => throw new NotImplementedException();

public virtual IIdentity? LogonUserIdentity => throw new NotImplementedException();

public virtual Encoding? ContentEncoding => throw new NotImplementedException();

public virtual string? UserHostName => throw new NotImplementedException();
Expand Down
Loading