Skip to content

Commit 00cba11

Browse files
author
samuel grahame
committed
added working asp ver
1 parent faf2080 commit 00cba11

File tree

11 files changed

+338
-15
lines changed

11 files changed

+338
-15
lines changed

ProjectWeb.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectWeb.Mysql", "Project
1111
EndProject
1212
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectWeb.Other", "ProjectWeb.Other\ProjectWeb.Other.csproj", "{E59D670B-707B-4FA1-976C-1AFAE8AAAEAE}"
1313
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectWebAspTest", "ProjectWebAspTest\ProjectWebAspTest.csproj", "{DE88DAB2-DD85-4124-BF3A-29020FFFB3FF}"
15+
EndProject
1416
Global
1517
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1618
Debug|Any CPU = Debug|Any CPU
@@ -33,6 +35,10 @@ Global
3335
{E59D670B-707B-4FA1-976C-1AFAE8AAAEAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
3436
{E59D670B-707B-4FA1-976C-1AFAE8AAAEAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
3537
{E59D670B-707B-4FA1-976C-1AFAE8AAAEAE}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{DE88DAB2-DD85-4124-BF3A-29020FFFB3FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{DE88DAB2-DD85-4124-BF3A-29020FFFB3FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{DE88DAB2-DD85-4124-BF3A-29020FFFB3FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{DE88DAB2-DD85-4124-BF3A-29020FFFB3FF}.Release|Any CPU.Build.0 = Release|Any CPU
3642
EndGlobalSection
3743
GlobalSection(SolutionProperties) = preSolution
3844
HideSolutionNode = FALSE

ProjectWeb/StateManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Net;
1010
using System.Text;
1111
using System.Threading.Tasks;
12+
using System.Web;
1213
using static ProjectWeb.Document;
1314

1415
namespace ProjectWeb
@@ -50,6 +51,7 @@ public async Task Push(string source)
5051
var options = ScriptOptions.Default.WithReferences(
5152
typeof(ProjectWeb.Mysql.Mysql).Assembly,
5253
typeof(MySqlConnection).Assembly,
54+
typeof(HttpContext).Assembly,
5355
typeof(ProjectWeb.Other.Extensions).Assembly,
5456
typeof(HttpListener).Assembly).WithImports(
5557
"ProjectWeb.Mysql", "MySql.Data.MySqlClient", "ProjectWeb.Other.Extensions").

ProjectWeb/WebHelper.cs

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Net;
8+
using System.Reflection;
89
using System.Text;
910
using System.Threading.Tasks;
1011
using System.Web;
@@ -40,14 +41,22 @@ public class RequestContextInfo
4041
public bool IsLocal;
4142
}
4243

44+
private static string DataFilePath => HttpRuntime.AppDomainAppVirtualPath != null ?
45+
HttpRuntime.AppDomainAppPath :
46+
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
47+
4348
public static RequestContextInfo GetRequestPath<T>(T context)
4449
{
4550
RequestContextInfo requestContextInfo = new RequestContextInfo();
4651
string fileRequest = "";
52+
HttpServerUtility Server = null;
53+
54+
bool isStandalone = false;
4755
if(context is HttpContext httpContext)
4856
{
49-
fileRequest = httpContext.Request.Url.LocalPath;
57+
fileRequest = httpContext.Request.Url.LocalPath;
5058
requestContextInfo.ContentType = httpContext.Request.ContentType;
59+
5160
requestContextInfo.StateManager = new StateManager()
5261
{
5362
Builder = new StringBuilder()
@@ -59,9 +68,12 @@ public static RequestContextInfo GetRequestPath<T>(T context)
5968
};
6069
requestContextInfo.IsLocal = httpContext.Request.IsLocal;
6170

71+
Server = httpContext.Server;
72+
6273
}
6374
else if (context is HttpListenerContext httpContextListener)
6475
{
76+
isStandalone = true;
6577
fileRequest = httpContextListener.Request.Url.LocalPath;
6678
requestContextInfo.ContentType = httpContextListener.Request.ContentType;
6779
requestContextInfo.StateManager = new StateManager()
@@ -77,18 +89,29 @@ public static RequestContextInfo GetRequestPath<T>(T context)
7789
}
7890
if (string.IsNullOrWhiteSpace(fileRequest) || fileRequest == "/")
7991
{
80-
fileRequest = "index.html";
92+
if(isStandalone)
93+
{
94+
fileRequest = "index.html";
95+
}
8196
}
8297
if (fileRequest.EndsWith(".html"))
8398
{
84-
requestContextInfo.Page = $"{Directory.GetCurrentDirectory()}/wwwroot/{fileRequest}";
99+
if(isStandalone)
100+
{
101+
requestContextInfo.Page = $"{Directory.GetCurrentDirectory()}/wwwroot/{fileRequest}";
102+
}
103+
else
104+
{
105+
requestContextInfo.Page = Server.MapPath($"~{fileRequest}");
106+
}
107+
85108
requestContextInfo.FileRequest = fileRequest;
86109
return requestContextInfo;
87110
}
88111
return null;
89112
}
90113

91-
public static async void ProcessAsync<T>(T context)
114+
public static async Task ProcessAsync<T>(T context)
92115
{
93116
// process request and make response
94117
HttpContext httpContext = context is HttpContext ? context as HttpContext : null;
@@ -110,12 +133,12 @@ public static async void ProcessAsync<T>(T context)
110133
string ct = requestInfo.ContentType;
111134
bool isHTML = ct == null || ct.ToLower().Trim() == "text/html";
112135
var stateManager = requestInfo.StateManager;
113-
if (isHTML)
136+
if (!UseDefault && isHTML)
114137
{
115138
stateManager.Builder.AppendLine("<html>");
116139
}
117-
var fileRequestToLower = requestInfo.FileRequest.ToLower();
118-
var absPath = Path.GetFullPath(fileRequestToLower);
140+
141+
var absPath = requestInfo.Page.ToLower();
119142

120143
if (StateCache.Cache.ContainsKey(absPath))
121144
{
@@ -124,7 +147,7 @@ public static async void ProcessAsync<T>(T context)
124147
else
125148
{
126149
var file = new Document.IncludedFiles();
127-
file.Files.Add(fileRequestToLower);
150+
file.Files.Add(absPath);
128151
TextReader tr = new StreamReader(requestInfo.Page);
129152

130153
await Document.ParseAsync(tr.ReadToEnd(), stateManager, file);
@@ -135,15 +158,18 @@ public static async void ProcessAsync<T>(T context)
135158
}
136159
}
137160

138-
if (isHTML && stateManager.Builder.Length > 0)
161+
if(!UseDefault)
139162
{
140-
ct = requestInfo.StateManager.Globals.GetResponseContentType();
141-
isHTML = ct == null || ct.ToLower().Trim() == "text/html";
142-
if (isHTML)
163+
if (isHTML && stateManager.Builder.Length > 0)
143164
{
144-
stateManager.Builder.AppendLine("</html>");
165+
ct = requestInfo.StateManager.Globals.GetResponseContentType();
166+
isHTML = ct == null || ct.ToLower().Trim() == "text/html";
167+
if (isHTML)
168+
{
169+
stateManager.Builder.AppendLine("</html>");
170+
}
145171
}
146-
}
172+
}
147173

148174
st.Stop();
149175

@@ -187,7 +213,7 @@ public static async void ProcessAsync<T>(T context)
187213
}
188214
if (UseDefault)
189215
{
190-
httpContext.Response.Close();
216+
httpContext.Response.Flush();
191217
}
192218
else
193219
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
6+
namespace ProjectWebAspTest
7+
{
8+
public class HandleAllRequestsHandler : IHttpHandler
9+
{
10+
public void ProcessRequest(HttpContext context)
11+
{
12+
var task = ProjectWeb.WebHelper.ProcessAsync(context);
13+
task.Wait();
14+
}
15+
16+
public bool IsReusable => true;
17+
}
18+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProductVersion>
8+
</ProductVersion>
9+
<SchemaVersion>2.0</SchemaVersion>
10+
<ProjectGuid>{DE88DAB2-DD85-4124-BF3A-29020FFFB3FF}</ProjectGuid>
11+
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
12+
<OutputType>Library</OutputType>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<RootNamespace>ProjectWebAspTest</RootNamespace>
15+
<AssemblyName>ProjectWebAspTest</AssemblyName>
16+
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
17+
<UseIISExpress>true</UseIISExpress>
18+
<Use64BitIISExpress />
19+
<IISExpressSSLPort />
20+
<IISExpressAnonymousAuthentication />
21+
<IISExpressWindowsAuthentication />
22+
<IISExpressUseClassicPipelineMode />
23+
<UseGlobalApplicationHostFile />
24+
<NuGetPackageImportStamp>
25+
</NuGetPackageImportStamp>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
28+
<DebugSymbols>true</DebugSymbols>
29+
<DebugType>full</DebugType>
30+
<Optimize>false</Optimize>
31+
<OutputPath>bin\</OutputPath>
32+
<DefineConstants>DEBUG;TRACE</DefineConstants>
33+
<ErrorReport>prompt</ErrorReport>
34+
<WarningLevel>4</WarningLevel>
35+
</PropertyGroup>
36+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
37+
<DebugSymbols>true</DebugSymbols>
38+
<DebugType>pdbonly</DebugType>
39+
<Optimize>true</Optimize>
40+
<OutputPath>bin\</OutputPath>
41+
<DefineConstants>TRACE</DefineConstants>
42+
<ErrorReport>prompt</ErrorReport>
43+
<WarningLevel>4</WarningLevel>
44+
</PropertyGroup>
45+
<ItemGroup>
46+
<Reference Include="Microsoft.CSharp" />
47+
<Reference Include="System.Web.DynamicData" />
48+
<Reference Include="System.Web.Entity" />
49+
<Reference Include="System.Web.ApplicationServices" />
50+
<Reference Include="System.ComponentModel.DataAnnotations" />
51+
<Reference Include="System" />
52+
<Reference Include="System.Data" />
53+
<Reference Include="System.Core" />
54+
<Reference Include="System.Data.DataSetExtensions" />
55+
<Reference Include="System.Web.Extensions" />
56+
<Reference Include="System.Xml.Linq" />
57+
<Reference Include="System.Drawing" />
58+
<Reference Include="System.Web" />
59+
<Reference Include="System.Xml" />
60+
<Reference Include="System.Configuration" />
61+
<Reference Include="System.Web.Services" />
62+
<Reference Include="System.EnterpriseServices" />
63+
</ItemGroup>
64+
<ItemGroup>
65+
<Reference Include="Microsoft.CodeDom.Providers.DotNetCompilerPlatform">
66+
<HintPath>..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll</HintPath>
67+
</Reference>
68+
</ItemGroup>
69+
<ItemGroup>
70+
<Content Include="Web.config" />
71+
<Content Include="index.html" />
72+
</ItemGroup>
73+
<ItemGroup>
74+
<Compile Include="HandleAllRequestsHandler.cs" />
75+
<Compile Include="Properties\AssemblyInfo.cs" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<None Include="packages.config" />
79+
<None Include="Web.Debug.config">
80+
<DependentUpon>Web.config</DependentUpon>
81+
</None>
82+
<None Include="Web.Release.config">
83+
<DependentUpon>Web.config</DependentUpon>
84+
</None>
85+
</ItemGroup>
86+
<ItemGroup>
87+
<ProjectReference Include="..\ProjectWeb\ProjectWeb.csproj">
88+
<Project>{13a5af97-6a21-4860-9463-09a8cdb3d57e}</Project>
89+
<Name>ProjectWeb</Name>
90+
</ProjectReference>
91+
</ItemGroup>
92+
<PropertyGroup>
93+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
94+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
95+
</PropertyGroup>
96+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
97+
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
98+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
99+
<ProjectExtensions>
100+
<VisualStudio>
101+
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
102+
<WebProjectProperties>
103+
<UseIIS>True</UseIIS>
104+
<AutoAssignPort>True</AutoAssignPort>
105+
<DevelopmentServerPort>62566</DevelopmentServerPort>
106+
<DevelopmentServerVPath>/</DevelopmentServerVPath>
107+
<IISUrl>http://localhost:62566/</IISUrl>
108+
<NTLMAuthentication>False</NTLMAuthentication>
109+
<UseCustomServer>False</UseCustomServer>
110+
<CustomServerUrl>
111+
</CustomServerUrl>
112+
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
113+
</WebProjectProperties>
114+
</FlavorProperties>
115+
</VisualStudio>
116+
</ProjectExtensions>
117+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
118+
<PropertyGroup>
119+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
120+
</PropertyGroup>
121+
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
122+
</Target>
123+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
124+
Other similar extension points exist, see Microsoft.Common.targets.
125+
<Target Name="BeforeBuild">
126+
</Target>
127+
<Target Name="AfterBuild">
128+
</Target>
129+
-->
130+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ProjectWebAspTest")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ProjectWebAspTest")]
13+
[assembly: AssemblyCopyright("Copyright © 2019")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("de88dab2-dd85-4124-bf3a-29020fffb3ff")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Revision and Build Numbers
33+
// by using the '*' as shown below:
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]

ProjectWebAspTest/Web.Debug.config

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- For more information on using web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=125889 -->
4+
5+
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
6+
<!--
7+
In the example below, the "SetAttributes" transform will change the value of
8+
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
9+
finds an attribute "name" that has a value of "MyDB".
10+
11+
<connectionStrings>
12+
<add name="MyDB"
13+
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
14+
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
15+
</connectionStrings>
16+
-->
17+
<system.web>
18+
<!--
19+
In the example below, the "Replace" transform will replace the entire
20+
<customErrors> section of your web.config file.
21+
Note that because there is only one customErrors section under the
22+
<system.web> node, there is no need to use the "xdt:Locator" attribute.
23+
24+
<customErrors defaultRedirect="GenericError.htm"
25+
mode="RemoteOnly" xdt:Transform="Replace">
26+
<error statusCode="500" redirect="InternalError.htm"/>
27+
</customErrors>
28+
-->
29+
</system.web>
30+
</configuration>

0 commit comments

Comments
 (0)