Skip to content

Commit 9bec0c7

Browse files
authored
Add HttpServerUtility.Transfer/Execute methods (#409)
This should help with some migrations that use the type to highlight they need to refactor.
1 parent 25b5147 commit 9bec0c7

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#if NETCOREAPP
5+
6+
using System.Collections.Specialized;
7+
using System.IO;
8+
9+
namespace Microsoft.AspNetCore.SystemWebAdapters;
10+
11+
internal interface ITransferRequestFeature
12+
{
13+
void Transfer(string path, bool preserveForm) => Execute(path, null, preserveForm);
14+
15+
void Execute(string path, TextWriter? writer, bool preserveForm);
16+
17+
void TransferRequest(string path, bool preserveForm, string? method, NameValueCollection? headers, bool preserveUser);
18+
}
19+
20+
#endif

src/Microsoft.AspNetCore.SystemWebAdapters/Constants.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,22 @@ internal static class Constants
1212
internal const string DisposeIsRegistered = "Object is registered for dispose with HttpContext";
1313

1414
internal const string CA1859 = "False positive fixed by https://github.com/dotnet/roslyn-analyzers/pull/6421 but not integrated in yet";
15+
16+
internal static class TransferRequest
17+
{
18+
public const string Message = "TransferRequest is not supported on ASP.NET Core";
19+
public const string DiagnosticId = "SYSWEB0001";
20+
}
21+
22+
internal static class Execute
23+
{
24+
public const string Message = "Execute is not supported on ASP.NET Core";
25+
public const string DiagnosticId = "SYSWEB0002";
26+
}
27+
28+
internal static class Transfer
29+
{
30+
public const string Message = "Transfer is not supported on ASP.NET Core";
31+
public const string DiagnosticId = "SYSWEB0003";
32+
}
1533
}

src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Header.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
1818
#pragma warning disable CA1063 // Implement IDisposable Correctly
1919
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
20+
#pragma warning disable CS0436 // Type conflicts with imported type
2021

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
#if NETSTANDARD
5+
namespace System;
6+
7+
/// <summary>
8+
/// An internal implementation to enable <see cref="DiagnosticId"/> on .NET Standard.
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum |
11+
AttributeTargets.Interface | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Delegate,
12+
Inherited = false)]
13+
internal sealed class ObsoleteAttribute : Attribute
14+
{
15+
public ObsoleteAttribute()
16+
{
17+
}
18+
19+
public ObsoleteAttribute(string? message)
20+
{
21+
Message = message;
22+
}
23+
24+
public string? Message { get; }
25+
26+
public bool IsError { get; }
27+
28+
public string? DiagnosticId { get; set; }
29+
30+
public string? UrlFormat { get; set; }
31+
}
32+
#endif

src/Microsoft.AspNetCore.SystemWebAdapters/Generated/Ref.Standard.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
1818
#pragma warning disable CA1063 // Implement IDisposable Correctly
1919
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
20+
#pragma warning disable CS0436 // Type conflicts with imported type
2021

2122
namespace System.Web
2223
{
@@ -578,8 +579,38 @@ public partial class HttpServerUtility
578579
internal HttpServerUtility() { }
579580
public string MachineName { get { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");} }
580581
public void ClearError() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
582+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
583+
[System.ObsoleteAttribute("Execute is not supported on ASP.NET Core", DiagnosticId="SYSWEB0002")]
584+
public void Execute(string path) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
585+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
586+
[System.ObsoleteAttribute("Execute is not supported on ASP.NET Core", DiagnosticId="SYSWEB0002")]
587+
public void Execute(string path, bool preserveForm) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
588+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
589+
[System.ObsoleteAttribute("Execute is not supported on ASP.NET Core", DiagnosticId="SYSWEB0002")]
590+
public void Execute(string path, System.IO.TextWriter writer) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
591+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
592+
[System.ObsoleteAttribute("Execute is not supported on ASP.NET Core", DiagnosticId="SYSWEB0002")]
593+
public void Execute(string path, System.IO.TextWriter writer, bool preserveForm) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
581594
public System.Exception GetLastError() { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
582595
public string MapPath(string path) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
596+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
597+
[System.ObsoleteAttribute("Transfer is not supported on ASP.NET Core", DiagnosticId="SYSWEB0003")]
598+
public void Transfer(string path) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
599+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
600+
[System.ObsoleteAttribute("Transfer is not supported on ASP.NET Core", DiagnosticId="SYSWEB0003")]
601+
public void Transfer(string path, bool preserveForm) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
602+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
603+
[System.ObsoleteAttribute("TransferRequest is not supported on ASP.NET Core", DiagnosticId="SYSWEB0001")]
604+
public void TransferRequest(string path) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
605+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
606+
[System.ObsoleteAttribute("TransferRequest is not supported on ASP.NET Core", DiagnosticId="SYSWEB0001")]
607+
public void TransferRequest(string path, bool preserveForm) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
608+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
609+
[System.ObsoleteAttribute("TransferRequest is not supported on ASP.NET Core", DiagnosticId="SYSWEB0001")]
610+
public void TransferRequest(string path, bool preserveForm, string method, System.Collections.Specialized.NameValueCollection headers) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
611+
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
612+
[System.ObsoleteAttribute("TransferRequest is not supported on ASP.NET Core", DiagnosticId="SYSWEB0001")]
613+
public void TransferRequest(string path, bool preserveForm, string method, System.Collections.Specialized.NameValueCollection headers, bool preserveUser) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
583614
public static byte[] UrlTokenDecode(string input) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
584615
public static string UrlTokenEncode(byte[] input) { throw new System.PlatformNotSupportedException("Only supported when running on ASP.NET Core or System.Web");}
585616
}

src/Microsoft.AspNetCore.SystemWebAdapters/Generated/TypeForwards.Framework.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member
1818
#pragma warning disable CA1063 // Implement IDisposable Correctly
1919
#pragma warning disable CA1816 // Dispose methods should call SuppressFinalize
20+
#pragma warning disable CS0436 // Type conflicts with imported type
2021

2122
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplication))]
2223
[assembly:System.Runtime.CompilerServices.TypeForwardedTo(typeof(System.Web.HttpApplicationState))]

src/Microsoft.AspNetCore.SystemWebAdapters/HttpServerUtility.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Collections.Specialized;
5+
using System.ComponentModel;
6+
using System.IO;
47
using System.Web.Hosting;
58
using Microsoft.AspNetCore.SystemWebAdapters;
69
using Microsoft.AspNetCore.WebUtilities;
@@ -83,4 +86,52 @@ public static string UrlTokenEncode(byte[] input)
8386

8487
return $"{encoded}{padding}";
8588
}
89+
90+
[Obsolete(Constants.Execute.Message, DiagnosticId = Constants.Execute.DiagnosticId)]
91+
[EditorBrowsable(EditorBrowsableState.Never)]
92+
public void Execute(string path) => Execute(path, null, preserveForm: true);
93+
94+
[Obsolete(Constants.Execute.Message, DiagnosticId = Constants.Execute.DiagnosticId)]
95+
[EditorBrowsable(EditorBrowsableState.Never)]
96+
public void Execute(string path, TextWriter writer) => Execute(path, writer, preserveForm: true);
97+
98+
[Obsolete(Constants.Execute.Message, DiagnosticId = Constants.Execute.DiagnosticId)]
99+
[EditorBrowsable(EditorBrowsableState.Never)]
100+
public void Execute(string path, bool preserveForm) => Execute(path, null, preserveForm);
101+
102+
[Obsolete(Constants.Execute.Message, DiagnosticId = Constants.Execute.DiagnosticId)]
103+
[EditorBrowsable(EditorBrowsableState.Never)]
104+
public void Execute(string path, TextWriter? writer, bool preserveForm) => _context.Features.GetRequired<ITransferRequestFeature>().Execute(path, writer, preserveForm);
105+
106+
[Obsolete(Constants.Transfer.Message, DiagnosticId = Constants.Transfer.DiagnosticId)]
107+
[EditorBrowsable(EditorBrowsableState.Never)]
108+
public void Transfer(string path) => Transfer(path, preserveForm: true);
109+
110+
[Obsolete(Constants.Transfer.Message, DiagnosticId = Constants.Transfer.DiagnosticId)]
111+
[EditorBrowsable(EditorBrowsableState.Never)]
112+
public void Transfer(string path, bool preserveForm)
113+
{
114+
_context.Features.GetRequired<ITransferRequestFeature>().Transfer(path, preserveForm);
115+
_context.Response.GetAdapter().End();
116+
}
117+
118+
[Obsolete(Constants.TransferRequest.Message, DiagnosticId = Constants.TransferRequest.DiagnosticId)]
119+
[EditorBrowsable(EditorBrowsableState.Never)]
120+
public void TransferRequest(string path)
121+
=> TransferRequest(path, false, null, null, preserveUser: true);
122+
123+
[Obsolete(Constants.TransferRequest.Message, DiagnosticId = Constants.TransferRequest.DiagnosticId)]
124+
[EditorBrowsable(EditorBrowsableState.Never)]
125+
public void TransferRequest(string path, bool preserveForm)
126+
=> TransferRequest(path, preserveForm, null, null, preserveUser: true);
127+
128+
[Obsolete(Constants.TransferRequest.Message, DiagnosticId = Constants.TransferRequest.DiagnosticId)]
129+
[EditorBrowsable(EditorBrowsableState.Never)]
130+
public void TransferRequest(string path, bool preserveForm, string? method, NameValueCollection? headers)
131+
=> TransferRequest(path, preserveForm, method, headers, preserveUser: true);
132+
133+
[Obsolete(Constants.TransferRequest.Message, DiagnosticId = Constants.TransferRequest.DiagnosticId)]
134+
[EditorBrowsable(EditorBrowsableState.Never)]
135+
public void TransferRequest(string path, bool preserveForm, string? method, NameValueCollection? headers, bool preserveUser)
136+
=> _context.Features.GetRequired<ITransferRequestFeature>().TransferRequest(path, preserveForm, method, headers, preserveUser);
86137
}

src/Microsoft.AspNetCore.SystemWebAdapters/Microsoft.AspNetCore.SystemWebAdapters.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<Compile Remove="**/*" />
3131
<Compile Include="Properties/PropertyInfo.cs" />
3232
<Compile Include="Generated/Ref.*.cs" />
33+
<Compile Include="Generated\Obsolete.cs" />
3334
<Compile Include="Adapters/SessionState/ISessionState.cs" />
3435
<Compile Include="IHtmlString.cs" />
3536
<Compile Include="HtmlString.cs" />

0 commit comments

Comments
 (0)