├── .gitattributes ├── .gitignore ├── AnyWebApp.sln ├── AnyWebApp ├── AnyWebApp.csproj ├── App.cs ├── AppConfig.cs ├── AppForm.Designer.cs ├── AppForm.cs ├── AppForm.resx ├── Injections │ └── Window.cs ├── Utils │ ├── HttpHeaderNames.cs │ ├── MimeUtils.cs │ ├── NativeMethods.cs │ └── SystemHelper.cs ├── app.manifest └── icon.ico ├── LICENSE.txt ├── README.md ├── README.zh.md └── assets ├── demo.html ├── icon128.png ├── icon256.png ├── icon512.png ├── icon64.png └── preview1.png /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /AnyWebApp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33723.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AnyWebApp", "AnyWebApp\AnyWebApp.csproj", "{832DF25F-D547-4DBE-A177-74724D2381DA}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{654ACF25-196C-4CCD-9B21-BA6848A76CF7}" 9 | ProjectSection(SolutionItems) = preProject 10 | README.md = README.md 11 | README.zh.md = README.zh.md 12 | EndProjectSection 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Release|Any CPU = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {832DF25F-D547-4DBE-A177-74724D2381DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {832DF25F-D547-4DBE-A177-74724D2381DA}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {832DF25F-D547-4DBE-A177-74724D2381DA}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {832DF25F-D547-4DBE-A177-74724D2381DA}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {56211BAE-B193-4682-828E-F28359552A22} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /AnyWebApp/AnyWebApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | WinExe 5 | net6.0-windows;net7.0-windows 6 | 1.0.2 7 | enable 8 | true 9 | AnyWebApp 10 | SlimeNull 11 | latest 12 | Run any web app without hosting a web server! 13 | app.manifest 14 | true 15 | icon.ico 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /AnyWebApp/App.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.IO; 4 | using System.Text.Json; 5 | using System.Text.RegularExpressions; 6 | using System.Windows.Forms; 7 | using Microsoft.Web.WebView2.Core; 8 | 9 | namespace AnyWebApp 10 | { 11 | internal static class App 12 | { 13 | const string AppConfigFile = "AppConfig.json"; 14 | 15 | public static readonly AppConfig Config; 16 | 17 | static App() 18 | { 19 | if (File.Exists(AppConfigFile)) 20 | Config = JsonSerializer.Deserialize(File.ReadAllText(AppConfigFile)) ?? throw new InvalidOperationException("AppConfig is null"); 21 | else 22 | Config = new AppConfig(); 23 | 24 | if (!File.Exists(AppConfigFile)) 25 | File.WriteAllText(AppConfigFile, JsonSerializer.Serialize(Config)); 26 | 27 | AppConfig.Check(Config); 28 | 29 | #if DEBUG 30 | Config.EnableDeveloperTools = true; 31 | Config.EnableAutoReload = true; 32 | Config.EnableFakeCors = true; 33 | #endif 34 | } 35 | 36 | /// 37 | /// The main entry point for the application. 38 | /// 39 | [STAThread] 40 | static void Main() 41 | { 42 | // To customize application configuration such as set high DPI settings or default font, 43 | // see https://aka.ms/applicationconfiguration. 44 | ApplicationConfiguration.Initialize(); 45 | Application.Run(new AppForm()); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /AnyWebApp/AppConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace AnyWebApp 9 | { 10 | public class AppConfig 11 | { 12 | public enum Theme 13 | { 14 | Auto, Light, Dark 15 | } 16 | 17 | public string Root { get; set; } = "wwwroot"; 18 | public string Scheme { get; set; } = "https"; 19 | public string UserAgent { get; set; }= string.Empty; 20 | public string StartupUri { get; set; } = "/"; 21 | public string StartupBackground { get; set; } = string.Empty; 22 | 23 | 24 | public bool EnableIndexFiles { get; set; } = true; 25 | public bool EnableDocumentFallbackFiles { get; set; } = false; 26 | 27 | public bool EnableDeveloperTools { get; set; } = false; 28 | public bool EnableZoomControl { get; set; } = false; 29 | public bool EnableAutoReload { get; set; } = false; 30 | public bool EnableStatusBar { get; set; } = false; 31 | public bool EnableAutoTitle { get; set; } = false; 32 | public bool EnableFakeCors { get; set; } = false; 33 | 34 | public string[] IndexFiles { get; set; } = new string[] 35 | { 36 | "index.htm", "index.html", "default.htm", "default.html" 37 | }; 38 | 39 | public string[] DocumentFallbackFiles { get; set; } = new string[] 40 | { 41 | "index.htm", "index.html", "default.htm", "default.html" 42 | }; 43 | 44 | public string[] FakeCorsTargetOrigins { get; set; } = new string[] 45 | { 46 | 47 | }; 48 | 49 | public string VirtualHostName { get; set; } = "localhost.app"; 50 | 51 | public string WindowTitle { get; set; } = "AnyWebApp"; 52 | public string WindowIcon { get; set; } = "icon.png"; 53 | public Theme WindowTheme { get; set; } = Theme.Auto; 54 | public int WindowWidth { get; set; } = -1; 55 | public int WindowHeight { get; set; } = -1; 56 | public bool WindowCenterStart { get; set; } = false; 57 | public double ZoomFactor { get; set; } = 1; 58 | 59 | public static readonly Regex RegexHostName = new Regex(@"^([a-zA-Z0-9-]+\.)([a-zA-Z]{2,})(\.[a-zA-Z]{2,})?$"); 60 | 61 | public static void Check(AppConfig config) 62 | { 63 | if (!RegexHostName.IsMatch(config.VirtualHostName)) 64 | throw new InvalidOperationException("AppConfig.VirtualHostName is not valid value"); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /AnyWebApp/AppForm.Designer.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using System.Windows.Forms; 3 | using Microsoft.Web.WebView2.WinForms; 4 | 5 | namespace AnyWebApp 6 | { 7 | partial class AppForm 8 | { 9 | /// 10 | /// Required designer variable. 11 | /// 12 | private System.ComponentModel.IContainer components = null; 13 | 14 | /// 15 | /// Clean up any resources being used. 16 | /// 17 | /// true if managed resources should be disposed; otherwise, false. 18 | protected override void Dispose(bool disposing) 19 | { 20 | if (disposing && (components != null)) 21 | { 22 | components.Dispose(); 23 | } 24 | base.Dispose(disposing); 25 | } 26 | 27 | #region Windows Form Designer generated code 28 | 29 | /// 30 | /// Required method for Designer support - do not modify 31 | /// the contents of this method with the code editor. 32 | /// 33 | private void InitializeComponent() 34 | { 35 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AppForm)); 36 | webView = new WebView2(); 37 | ((System.ComponentModel.ISupportInitialize)webView).BeginInit(); 38 | SuspendLayout(); 39 | // 40 | // webView 41 | // 42 | webView.AllowExternalDrop = true; 43 | webView.CreationProperties = null; 44 | webView.DefaultBackgroundColor = Color.White; 45 | webView.Dock = DockStyle.Fill; 46 | webView.Location = new Point(0, 0); 47 | webView.Name = "webView"; 48 | webView.Size = new Size(1178, 744); 49 | webView.TabIndex = 0; 50 | webView.ZoomFactor = 1D; 51 | webView.CoreWebView2InitializationCompleted += CoreWebView2InitializationCompleted; 52 | // 53 | // AppForm 54 | // 55 | AutoScaleDimensions = new SizeF(10F, 25F); 56 | AutoScaleMode = AutoScaleMode.Font; 57 | ClientSize = new Size(1178, 744); 58 | Controls.Add(webView); 59 | Icon = (Icon)resources.GetObject("$this.Icon"); 60 | Name = "AppForm"; 61 | Text = "AppForm"; 62 | ((System.ComponentModel.ISupportInitialize)webView).EndInit(); 63 | ResumeLayout(false); 64 | } 65 | 66 | #endregion 67 | 68 | private WebView2 webView; 69 | } 70 | } -------------------------------------------------------------------------------- /AnyWebApp/AppForm.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/AnyWebApp/AppForm.cs -------------------------------------------------------------------------------- /AnyWebApp/Injections/Window.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Forms; 8 | 9 | namespace AnyWebApp.Injections 10 | { 11 | [ComVisible(true)] 12 | public class Window 13 | { 14 | private readonly Form form; 15 | 16 | public Window(Form form) 17 | { 18 | this.form = form; 19 | } 20 | 21 | public int Width { get => form.Width; set => form.Width = value; } 22 | public int Height { get => form.Height; set => form.Height = value; } 23 | public string Title { get => form.Text; set => form.Text = value; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /AnyWebApp/Utils/HttpHeaderNames.cs: -------------------------------------------------------------------------------- 1 | namespace AnyWebApp.Utils 2 | { 3 | public class HttpHeaderNames 4 | { 5 | public const string Origin = "Origin"; 6 | 7 | public const string AccessControlAllowOrigin = "Access-Control-Allow-Origin"; 8 | public const string AccessControlAllowMethods = "Access-Control-Allow-Methods"; 9 | public const string AccessControlAllowHeaders = "Access-Control-Allow-Headers"; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /AnyWebApp/Utils/MimeUtils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics.CodeAnalysis; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AnyWebApp.Utils 10 | { 11 | public static class MimeUtils 12 | { 13 | public static Dictionary Extensions { get; } = new Dictionary(StringComparer.OrdinalIgnoreCase) 14 | { 15 | { ".323", "text/h323" }, 16 | { ".3g2", "video/3gpp2" }, 17 | { ".3gp", "video/3gpp" }, 18 | { ".7z", "application/x-7z-compressed" }, 19 | { ".aab", "application/x-authorware-bin" }, 20 | { ".aac", "audio/aac" }, 21 | { ".aam", "application/x-authorware-map" }, 22 | { ".aas", "application/x-authorware-seg" }, 23 | { ".abc", "text/vnd.abc" }, 24 | { ".acgi", "text/html" }, 25 | { ".acx", "application/internet-property-stream" }, 26 | { ".afl", "video/animaflex" }, 27 | { ".ai", "application/postscript" }, 28 | { ".aif", "audio/aiff" }, 29 | { ".aifc", "audio/aiff" }, 30 | { ".aiff", "audio/aiff" }, 31 | { ".aim", "application/x-aim" }, 32 | { ".aip", "text/x-audiosoft-intra" }, 33 | { ".ani", "application/x-navi-animation" }, 34 | { ".aos", "application/x-nokia-9000-communicator-add-on-software" }, 35 | { ".appcache", "text/cache-manifest" }, 36 | { ".application", "application/x-ms-application" }, 37 | { ".aps", "application/mime" }, 38 | { ".art", "image/x-jg" }, 39 | { ".asf", "video/x-ms-asf" }, 40 | { ".asm", "text/x-asm" }, 41 | { ".asp", "text/asp" }, 42 | { ".asr", "video/x-ms-asf" }, 43 | { ".asx", "application/x-mplayer2" }, 44 | { ".atom", "application/atom+xml" }, 45 | { ".au", "audio/x-au" }, 46 | { ".avi", "video/avi" }, 47 | { ".avs", "video/avs-video" }, 48 | { ".axs", "application/olescript" }, 49 | { ".azw", "application/vnd.amazon.ebook" }, 50 | { ".bas", "text/plain" }, 51 | { ".bcpio", "application/x-bcpio" }, 52 | { ".bin", "application/octet-stream" }, 53 | { ".bm", "image/bmp" }, 54 | { ".bmp", "image/bmp" }, 55 | { ".boo", "application/book" }, 56 | { ".book", "application/book" }, 57 | { ".boz", "application/x-bzip2" }, 58 | { ".bsh", "application/x-bsh" }, 59 | { ".bz2", "application/x-bzip2" }, 60 | { ".bz", "application/x-bzip" }, 61 | { ".cat", "application/vnd.ms-pki.seccat" }, 62 | { ".ccad", "application/clariscad" }, 63 | { ".cco", "application/x-cocoa" }, 64 | { ".cc", "text/plain" }, 65 | { ".cdf", "application/cdf" }, 66 | { ".cer", "application/pkix-cert" }, 67 | { ".cha", "application/x-chat" }, 68 | { ".chat", "application/x-chat" }, 69 | { ".chm", "application/vnd.ms-htmlhelp" }, 70 | { ".class", "application/x-java-applet" }, 71 | { ".clp", "application/x-msclip" }, 72 | { ".cmx", "image/x-cmx" }, 73 | { ".cod", "image/cis-cod" }, 74 | { ".coffee", "text/x-coffeescript" }, 75 | { ".conf", "text/plain" }, 76 | { ".cpio", "application/x-cpio" }, 77 | { ".cpp", "text/plain" }, 78 | { ".cpt", "application/x-cpt" }, 79 | { ".crd", "application/x-mscardfile" }, 80 | { ".crl", "application/pkix-crl" }, 81 | { ".crt", "application/pkix-cert" }, 82 | { ".csh", "application/x-csh" }, 83 | { ".css", "text/css" }, 84 | { ".csv", "text/csv" }, 85 | { ".cs", "text/plain" }, 86 | { ".c", "text/plain" }, 87 | { ".c++", "text/plain" }, 88 | { ".cxx", "text/plain" }, 89 | { ".dart", "application/dart" }, 90 | { ".dcr", "application/x-director" }, 91 | { ".deb", "application/x-deb" }, 92 | { ".deepv", "application/x-deepv" }, 93 | { ".def", "text/plain" }, 94 | { ".deploy", "application/octet-stream" }, 95 | { ".der", "application/x-x509-ca-cert" }, 96 | { ".dib", "image/bmp" }, 97 | { ".dif", "video/x-dv" }, 98 | { ".dir", "application/x-director" }, 99 | { ".disco", "text/xml" }, 100 | { ".dll", "application/x-msdownload" }, 101 | { ".dl", "video/dl" }, 102 | { ".doc", "application/msword" }, 103 | { ".docm", "application/vnd.ms-word.document.macroEnabled.12" }, 104 | { ".docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document" }, 105 | { ".dot", "application/msword" }, 106 | { ".dotm", "application/vnd.ms-word.template.macroEnabled.12" }, 107 | { ".dotx", "application/vnd.openxmlformats-officedocument.wordprocessingml.template" }, 108 | { ".dp", "application/commonground" }, 109 | { ".drw", "application/drafting" }, 110 | { ".dtd", "application/xml-dtd" }, 111 | { ".dvi", "application/x-dvi" }, 112 | { ".dv", "video/x-dv" }, 113 | { ".dwg", "application/acad" }, 114 | { ".dxf", "application/dxf" }, 115 | { ".dxr", "application/x-director" }, 116 | { ".el", "text/x-script.elisp" }, 117 | { ".elc", "application/x-elc" }, 118 | { ".emf", "image/emf" }, 119 | { ".eml", "message/rfc822" }, 120 | { ".eot", "application/vnd.bw-fontobject" }, 121 | { ".eps", "application/postscript" }, 122 | { ".epub", "application/epub+zip" }, 123 | { ".es", "application/x-esrehber" }, 124 | { ".etx", "text/x-setext" }, 125 | { ".evy", "application/envoy" }, 126 | { ".exe", "application/octet-stream" }, 127 | { ".f77", "text/plain" }, 128 | { ".f90", "text/plain" }, 129 | { ".fdf", "application/vnd.fdf" }, 130 | { ".fif", "image/fif" }, 131 | { ".flac", "audio/x-flac" }, 132 | { ".fli", "video/fli" }, 133 | { ".flx", "text/vnd.fmi.flexstor" }, 134 | { ".fmf", "video/x-atomic3d-feature" }, 135 | { ".for", "text/plain" }, 136 | { ".fpx", "image/vnd.fpx" }, 137 | { ".frl", "application/freeloader" }, 138 | { ".fsx", "application/fsharp-script" }, 139 | { ".g3", "image/g3fax" }, 140 | { ".gif", "image/gif" }, 141 | { ".gl", "video/gl" }, 142 | { ".gsd", "audio/x-gsm" }, 143 | { ".gsm", "audio/x-gsm" }, 144 | { ".gsp", "application/x-gsp" }, 145 | { ".gss", "application/x-gss" }, 146 | { ".gtar", "application/x-gtar" }, 147 | { ".g", "text/plain" }, 148 | { ".gz", "application/x-gzip" }, 149 | { ".gzip", "application/x-gzip" }, 150 | { ".hdf", "application/x-hdf" }, 151 | { ".help", "application/x-helpfile" }, 152 | { ".hgl", "application/vnd.hp-HPGL" }, 153 | { ".hh", "text/plain" }, 154 | { ".hlb", "text/x-script" }, 155 | { ".hlp", "application/x-helpfile" }, 156 | { ".hpg", "application/vnd.hp-HPGL" }, 157 | { ".hpgl", "application/vnd.hp-HPGL" }, 158 | { ".hqx", "application/binhex" }, 159 | { ".hta", "application/hta" }, 160 | { ".htc", "text/x-component" }, 161 | { ".h", "text/plain" }, 162 | { ".htmls", "text/html" }, 163 | { ".html", "text/html" }, 164 | { ".htm", "text/html" }, 165 | { ".htt", "text/webviewhtml" }, 166 | { ".htx", "text/html" }, 167 | { ".ico", "image/vnd.microsoft.icon" }, 168 | { ".ics", "text/calendar" }, 169 | { ".idc", "text/plain" }, 170 | { ".ief", "image/ief" }, 171 | { ".iefs", "image/ief" }, 172 | { ".iges", "model/iges" }, 173 | { ".igs", "model/iges" }, 174 | { ".iii", "application/x-iphone" }, 175 | { ".ima", "application/x-ima" }, 176 | { ".imap", "application/x-httpd-imap" }, 177 | { ".inf", "application/inf" }, 178 | { ".ins", "application/x-internett-signup" }, 179 | { ".ip", "application/x-ip2" }, 180 | { ".isp", "application/x-internet-signup" }, 181 | { ".isu", "video/x-isvideo" }, 182 | { ".it", "audio/it" }, 183 | { ".iv", "application/x-inventor" }, 184 | { ".ivf", "video/x-ivf" }, 185 | { ".ivy", "application/x-livescreen" }, 186 | { ".jam", "audio/x-jam" }, 187 | { ".jar", "application/java-archive" }, 188 | { ".java", "text/plain" }, 189 | { ".jav", "text/plain" }, 190 | { ".jcm", "application/x-java-commerce" }, 191 | { ".jfif", "image/jpeg" }, 192 | { ".jfif-tbnl", "image/jpeg" }, 193 | { ".jpeg", "image/jpeg" }, 194 | { ".jpe", "image/jpeg" }, 195 | { ".jpg", "image/jpeg" }, 196 | { ".jps", "image/x-jps" }, 197 | { ".js", "text/javascript" }, 198 | { ".json", "application/json" }, 199 | { ".jsonld", "application/ld+json" }, 200 | { ".jut", "image/jutvision" }, 201 | { ".kar", "audio/midi" }, 202 | { ".ksh", "text/x-script.ksh" }, 203 | { ".la", "audio/nspaudio" }, 204 | { ".lam", "audio/x-liveaudio" }, 205 | { ".latex", "application/x-latex" }, 206 | { ".list", "text/plain" }, 207 | { ".lma", "audio/nspaudio" }, 208 | { ".log", "text/plain" }, 209 | { ".lsp", "application/x-lisp" }, 210 | { ".lst", "text/plain" }, 211 | { ".lsx", "text/x-la-asf" }, 212 | { ".ltx", "application/x-latex" }, 213 | { ".m13", "application/x-msmediaview" }, 214 | { ".m14", "application/x-msmediaview" }, 215 | { ".m1v", "video/mpeg" }, 216 | { ".m2a", "audio/mpeg" }, 217 | { ".m2v", "video/mpeg" }, 218 | { ".m3u", "audio/x-mpequrl" }, 219 | { ".m4a", "audio/mp4" }, 220 | { ".m4v", "video/mp4" }, 221 | { ".man", "application/x-troff-man" }, 222 | { ".manifest", "application/x-ms-manifest" }, 223 | { ".map", "application/x-navimap" }, 224 | { ".mar", "text/plain" }, 225 | { ".markdown", "text/markdown" }, 226 | { ".mbd", "application/mbedlet" }, 227 | { ".mc$", "application/x-magic-cap-package-1.0" }, 228 | { ".mcd", "application/mcad" }, 229 | { ".mcf", "image/vasa" }, 230 | { ".mcp", "application/netmc" }, 231 | { ".md", "text/markdown" }, 232 | { ".mdb", "application/x-msaccess" }, 233 | { ".mesh", "model/mesh" }, 234 | { ".me", "application/x-troff-me" }, 235 | { ".mid", "audio/midi" }, 236 | { ".midi", "audio/midi" }, 237 | { ".mif", "application/x-mif" }, 238 | { ".mjf", "audio/x-vnd.AudioExplosion.MjuiceMediaFile" }, 239 | { ".mjpg", "video/x-motion-jpeg" }, 240 | { ".mjs", "text/javascript" }, 241 | { ".mkv", "video/x-matroska" }, 242 | { ".mm", "application/base64" }, 243 | { ".mme", "application/base64" }, 244 | { ".mny", "application/x-msmoney" }, 245 | { ".mod", "audio/mod" }, 246 | { ".mov", "video/quicktime" }, 247 | { ".movie", "video/x-sgi-movie" }, 248 | { ".mp2", "video/mpeg" }, 249 | { ".mp3", "audio/mpeg" }, 250 | { ".mp4", "video/mp4" }, 251 | { ".mp4a", "audio/mp4" }, 252 | { ".mp4v", "video/mp4" }, 253 | { ".mpa", "audio/mpeg" }, 254 | { ".mpc", "application/x-project" }, 255 | { ".mpeg", "video/mpeg" }, 256 | { ".mpe", "video/mpeg" }, 257 | { ".mpga", "audio/mpeg" }, 258 | { ".mpg", "video/mpeg" }, 259 | { ".mpp", "application/vnd.ms-project" }, 260 | { ".mpt", "application/x-project" }, 261 | { ".mpv2", "video/mpeg" }, 262 | { ".mpv", "application/x-project" }, 263 | { ".mpx", "application/x-project" }, 264 | { ".mrc", "application/marc" }, 265 | { ".ms", "application/x-troff-ms" }, 266 | { ".msg", "application/vnd.ms-outlook" }, 267 | { ".msh", "model/mesh" }, 268 | { ".m", "text/plain" }, 269 | { ".mvb", "application/x-msmediaview" }, 270 | { ".mv", "video/x-sgi-movie" }, 271 | { ".mzz", "application/x-vnd.AudioExplosion.mzz" }, 272 | { ".nap", "image/naplps" }, 273 | { ".naplps", "image/naplps" }, 274 | { ".nc", "application/x-netcdf" }, 275 | { ".ncm", "application/vnd.nokia.configuration-message" }, 276 | { ".niff", "image/x-niff" }, 277 | { ".nif", "image/x-niff" }, 278 | { ".nix", "application/x-mix-transfer" }, 279 | { ".nsc", "application/x-conference" }, 280 | { ".nvd", "application/x-navidoc" }, 281 | { ".nws", "message/rfc822" }, 282 | { ".oda", "application/oda" }, 283 | { ".odp", "application/vnd.oasis.opendocument.presentation" }, 284 | { ".ods", "application/vnd.oasis.opendocument.spreadsheet" }, 285 | { ".odt", "application/vnd.oasis.opendocument.text" }, 286 | { ".oga", "audio/ogg" }, 287 | { ".ogg", "audio/ogg" }, 288 | { ".ogv", "video/ogg" }, 289 | { ".ogx", "application/ogg" }, 290 | { ".omc", "application/x-omc" }, 291 | { ".omcd", "application/x-omcdatamaker" }, 292 | { ".omcr", "application/x-omcregerator" }, 293 | { ".opus", "audio/opus" }, 294 | { ".otf", "font/otf" }, 295 | { ".oxps", "application/oxps" }, 296 | { ".p10", "application/pkcs10" }, 297 | { ".p12", "application/pkcs-12" }, 298 | { ".p7a", "application/x-pkcs7-signature" }, 299 | { ".p7b", "application/x-pkcs7-certificates" }, 300 | { ".p7c", "application/pkcs7-mime" }, 301 | { ".p7m", "application/pkcs7-mime" }, 302 | { ".p7r", "application/x-pkcs7-certreqresp" }, 303 | { ".p7s", "application/pkcs7-signature" }, 304 | { ".part", "application/pro_eng" }, 305 | { ".pas", "text/pascal" }, 306 | { ".pbm", "image/x-portable-bitmap" }, 307 | { ".pcl", "application/x-pcl" }, 308 | { ".pct", "image/x-pict" }, 309 | { ".pcx", "image/x-pcx" }, 310 | { ".pdf", "application/pdf" }, 311 | { ".pfx", "application/x-pkcs12" }, 312 | { ".pgm", "image/x-portable-graymap" }, 313 | { ".pic", "image/pict" }, 314 | { ".pict", "image/pict" }, 315 | { ".pkg", "application/x-newton-compatible-pkg" }, 316 | { ".pko", "application/vnd.ms-pki.pko" }, 317 | { ".pl", "text/plain" }, 318 | { ".plx", "application/x-PiXCLscript" }, 319 | { ".pm4", "application/x-pagemaker" }, 320 | { ".pm5", "application/x-pagemaker" }, 321 | { ".pma", "application/x-perfmon" }, 322 | { ".pmc", "application/x-perfmon" }, 323 | { ".pm", "image/x-xpixmap" }, 324 | { ".pml", "application/x-perfmon" }, 325 | { ".pmr", "application/x-perfmon" }, 326 | { ".pmw", "application/x-perfmon" }, 327 | { ".png", "image/png" }, 328 | { ".pnm", "application/x-portable-anymap" }, 329 | { ".pot", "application/vnd.ms-powerpoint" }, 330 | { ".potm", "application/vnd.ms-powerpoint.template.macroEnabled.12" }, 331 | { ".potx", "application/vnd.openxmlformats-officedocument.presentationml.template" }, 332 | { ".pov", "model/x-pov" }, 333 | { ".ppa", "application/vnd.ms-powerpoint" }, 334 | { ".ppam", "application/vnd.ms-powerpoint.addin.macroEnabled.12" }, 335 | { ".ppm", "image/x-portable-pixmap" }, 336 | { ".pps", "application/vnd.ms-powerpoint" }, 337 | { ".ppsm", "application/vnd.ms-powerpoint.slideshow.macroEnabled.12" }, 338 | { ".ppsx", "application/vnd.openxmlformats-officedocument.presentationml.slideshow" }, 339 | { ".ppt", "application/vnd.ms-powerpoint" }, 340 | { ".pptm", "application/vnd.ms-powerpoint.presentation.macroEnabled.12" }, 341 | { ".pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation" }, 342 | { ".ppz", "application/mspowerpoint" }, 343 | { ".pre", "application/x-freelance" }, 344 | { ".prf", "application/pics-rules" }, 345 | { ".prt", "application/pro_eng" }, 346 | { ".ps", "application/postscript" }, 347 | { ".p", "text/x-pascal" }, 348 | { ".pub", "application/x-mspublisher" }, 349 | { ".pwz", "application/vnd.ms-powerpoint" }, 350 | { ".pyc", "application/x-bytecode.python" }, 351 | { ".py", "text/x-script.phyton" }, 352 | { ".qcp", "audio/vnd.qcelp" }, 353 | { ".qif", "image/x-quicktime" }, 354 | { ".qtc", "video/x-qtc" }, 355 | { ".qtif", "image/x-quicktime" }, 356 | { ".qti", "image/x-quicktime" }, 357 | { ".qt", "video/quicktime" }, 358 | { ".ra", "audio/x-pn-realaudio" }, 359 | { ".ram", "audio/x-pn-realaudio" }, 360 | { ".rar", "application/vnd.rar" }, 361 | { ".ras", "application/x-cmu-raster" }, 362 | { ".rast", "image/cmu-raster" }, 363 | { ".rexx", "text/x-script.rexx" }, 364 | { ".rf", "image/vnd.rn-realflash" }, 365 | { ".rgb", "image/x-rgb" }, 366 | { ".rm", "application/vnd.rn-realmedia" }, 367 | { ".rmi", "audio/mid" }, 368 | { ".rmm", "audio/x-pn-realaudio" }, 369 | { ".rmp", "audio/x-pn-realaudio" }, 370 | { ".rng", "application/ringing-tones" }, 371 | { ".rnx", "application/vnd.rn-realplayer" }, 372 | { ".roff", "application/x-troff" }, 373 | { ".rp", "image/vnd.rn-realpix" }, 374 | { ".rpm", "audio/x-pn-realaudio-plugin" }, 375 | { ".rss", "application/rss+xml" }, 376 | { ".rtf", "text/rtf" }, 377 | { ".rt", "text/richtext" }, 378 | { ".rtx", "text/richtext" }, 379 | { ".rv", "video/vnd.rn-realvideo" }, 380 | { ".s3m", "audio/s3m" }, 381 | { ".sbk", "application/x-tbook" }, 382 | { ".scd", "application/x-msschedule" }, 383 | { ".scm", "application/x-lotusscreencam" }, 384 | { ".sct", "text/scriptlet" }, 385 | { ".sdml", "text/plain" }, 386 | { ".sdp", "application/sdp" }, 387 | { ".sdr", "application/sounder" }, 388 | { ".sea", "application/sea" }, 389 | { ".set", "application/set" }, 390 | { ".setpay", "application/set-payment-initiation" }, 391 | { ".setreg", "application/set-registration-initiation" }, 392 | { ".sgml", "text/sgml" }, 393 | { ".sgm", "text/sgml" }, 394 | { ".shar", "application/x-bsh" }, 395 | { ".sh", "text/x-script.sh" }, 396 | { ".shtml", "text/html" }, 397 | { ".sid", "audio/x-psid" }, 398 | { ".silo", "model/mesh" }, 399 | { ".sit", "application/x-sit" }, 400 | { ".skd", "application/x-koan" }, 401 | { ".skm", "application/x-koan" }, 402 | { ".skp", "application/x-koan" }, 403 | { ".skt", "application/x-koan" }, 404 | { ".sl", "application/x-seelogo" }, 405 | { ".smi", "application/smil" }, 406 | { ".smil", "application/smil" }, 407 | { ".snd", "audio/basic" }, 408 | { ".sol", "application/solids" }, 409 | { ".spc", "application/x-pkcs7-certificates" }, 410 | { ".spl", "application/futuresplash" }, 411 | { ".spr", "application/x-sprite" }, 412 | { ".sprite", "application/x-sprite" }, 413 | { ".spx", "audio/ogg" }, 414 | { ".src", "application/x-wais-source" }, 415 | { ".ssi", "text/x-server-parsed-html" }, 416 | { ".ssm", "application/streamingmedia" }, 417 | { ".sst", "application/vnd.ms-pki.certstore" }, 418 | { ".step", "application/step" }, 419 | { ".s", "text/x-asm" }, 420 | { ".stl", "application/sla" }, 421 | { ".stm", "text/html" }, 422 | { ".stp", "application/step" }, 423 | { ".sv4cpio", "application/x-sv4cpio" }, 424 | { ".sv4crc", "application/x-sv4crc" }, 425 | { ".svf", "image/x-dwg" }, 426 | { ".svg", "image/svg+xml" }, 427 | { ".svr", "application/x-world" }, 428 | { ".swf", "application/x-shockwave-flash" }, 429 | { ".talk", "text/x-speech" }, 430 | { ".t", "application/x-troff" }, 431 | { ".tar", "application/x-tar" }, 432 | { ".tbk", "application/toolbook" }, 433 | { ".tcl", "text/x-script.tcl" }, 434 | { ".tcsh", "text/x-script.tcsh" }, 435 | { ".tex", "application/x-tex" }, 436 | { ".texi", "application/x-texinfo" }, 437 | { ".texinfo", "application/x-texinfo" }, 438 | { ".text", "text/plain" }, 439 | { ".tgz", "application/x-compressed" }, 440 | { ".tiff", "image/tiff" }, 441 | { ".tif", "image/tiff" }, 442 | { ".tr", "application/x-troff" }, 443 | { ".trm", "application/x-msterminal" }, 444 | { ".ts", "application/typescript" }, 445 | { ".tsi", "audio/tsp-audio" }, 446 | { ".tsp", "audio/tsplayer" }, 447 | { ".tsv", "text/tab-separated-values" }, 448 | { ".ttc", "font/collection" }, 449 | { ".ttf", "font/ttf" }, 450 | { ".txt", "text/plain" }, 451 | { ".uil", "text/x-uil" }, 452 | { ".uls", "text/iuls" }, 453 | { ".unis", "text/uri-list" }, 454 | { ".uni", "text/uri-list" }, 455 | { ".unv", "application/i-deas" }, 456 | { ".uris", "text/uri-list" }, 457 | { ".uri", "text/uri-list" }, 458 | { ".ustar", "multipart/x-ustar" }, 459 | { ".uue", "text/x-uuencode" }, 460 | { ".uu", "text/x-uuencode" }, 461 | { ".vcd", "application/x-cdlink" }, 462 | { ".vcf", "text/vcard" }, 463 | { ".vcard", "text/vcard" }, 464 | { ".vcs", "text/x-vcalendar" }, 465 | { ".vda", "application/vda" }, 466 | { ".vdo", "video/vdo" }, 467 | { ".vew", "application/groupwise" }, 468 | { ".vivo", "video/vnd.vivo" }, 469 | { ".viv", "video/vnd.vivo" }, 470 | { ".vmd", "application/vocaltec-media-desc" }, 471 | { ".vmf", "application/vocaltec-media-file" }, 472 | { ".voc", "audio/voc" }, 473 | { ".vos", "video/vosaic" }, 474 | { ".vox", "audio/voxware" }, 475 | { ".vqe", "audio/x-twinvq-plugin" }, 476 | { ".vqf", "audio/x-twinvq" }, 477 | { ".vql", "audio/x-twinvq-plugin" }, 478 | { ".vrml", "application/x-vrml" }, 479 | { ".vsd", "application/x-visio" }, 480 | { ".vst", "application/x-visio" }, 481 | { ".vsw", "application/x-visio" }, 482 | { ".w60", "application/wordperfect6.0" }, 483 | { ".w61", "application/wordperfect6.1" }, 484 | { ".w6w", "application/msword" }, 485 | { ".wav", "audio/wav" }, 486 | { ".wb1", "application/x-qpro" }, 487 | { ".wbmp", "image/vnd.wap.wbmp" }, 488 | { ".wcm", "application/vnd.ms-works" }, 489 | { ".wdb", "application/vnd.ms-works" }, 490 | { ".web", "application/vnd.xara" }, 491 | { ".weba", "audio/webm" }, 492 | { ".webm", "video/webm" }, 493 | { ".webp", "image/webp" }, 494 | { ".wiz", "application/msword" }, 495 | { ".wk1", "application/x-123" }, 496 | { ".wks", "application/vnd.ms-works" }, 497 | { ".wmf", "image/wmf" }, 498 | { ".wmlc", "application/vnd.wap.wmlc" }, 499 | { ".wmlsc", "application/vnd.wap.wmlscriptc" }, 500 | { ".wmls", "text/vnd.wap.wmlscript" }, 501 | { ".wml", "text/vnd.wap.wml" }, 502 | { ".wmp", "video/x-ms-wmp" }, 503 | { ".wmv", "video/x-ms-wmv" }, 504 | { ".wmx", "video/x-ms-wmx" }, 505 | { ".woff", "font/woff" }, 506 | { ".woff2", "font/woff2" }, 507 | { ".word", "application/msword" }, 508 | { ".wp5", "application/wordperfect" }, 509 | { ".wp6", "application/wordperfect" }, 510 | { ".wp", "application/wordperfect" }, 511 | { ".wpd", "application/wordperfect" }, 512 | { ".wps", "application/vnd.ms-works" }, 513 | { ".wq1", "application/x-lotus" }, 514 | { ".wri", "application/mswrite" }, 515 | { ".wrl", "application/x-world" }, 516 | { ".wrz", "model/vrml" }, 517 | { ".wsc", "text/scriplet" }, 518 | { ".wsdl", "text/xml" }, 519 | { ".wsrc", "application/x-wais-source" }, 520 | { ".wtk", "application/x-wintalk" }, 521 | { ".wvx", "video/x-ms-wvx" }, 522 | { ".x3d", "model/x3d+xml" }, 523 | { ".x3db", "model/x3d+fastinfoset" }, 524 | { ".x3dv", "model/x3d-vrml" }, 525 | { ".xaml", "application/xaml+xml" }, 526 | { ".xap", "application/x-silverlight-app" }, 527 | { ".xbap", "application/x-ms-xbap" }, 528 | { ".xbm", "image/x-xbitmap" }, 529 | { ".xdr", "video/x-amt-demorun" }, 530 | { ".xht", "application/xhtml+xml" }, 531 | { ".xhtml", "application/xhtml+xml" }, 532 | { ".xif", "image/vnd.xiff" }, 533 | { ".xla", "application/vnd.ms-excel" }, 534 | { ".xlam", "application/vnd.ms-excel.addin.macroEnabled.12" }, 535 | { ".xl", "application/excel" }, 536 | { ".xlb", "application/excel" }, 537 | { ".xlc", "application/excel" }, 538 | { ".xld", "application/excel" }, 539 | { ".xlk", "application/excel" }, 540 | { ".xll", "application/excel" }, 541 | { ".xlm", "application/excel" }, 542 | { ".xls", "application/vnd.ms-excel" }, 543 | { ".xlsb", "application/vnd.ms-excel.sheet.binary.macroEnabled.12" }, 544 | { ".xlsm", "application/vnd.ms-excel.sheet.macroEnabled.12" }, 545 | { ".xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }, 546 | { ".xlt", "application/vnd.ms-excel" }, 547 | { ".xltm", "application/vnd.ms-excel.template.macroEnabled.12" }, 548 | { ".xltx", "application/vnd.openxmlformats-officedocument.spreadsheetml.template" }, 549 | { ".xlv", "application/excel" }, 550 | { ".xlw", "application/excel" }, 551 | { ".xm", "audio/xm" }, 552 | { ".xml", "text/xml" }, 553 | { ".xpi", "application/x-xpinstall" }, 554 | { ".xpix", "application/x-vnd.ls-xpix" }, 555 | { ".xpm", "image/xpm" }, 556 | { ".xps", "application/vnd.ms-xpsdocument" }, 557 | { ".x-png", "image/png" }, 558 | { ".xsd", "text/xml" }, 559 | { ".xsl", "text/xml" }, 560 | { ".xslt", "text/xml" }, 561 | { ".xsr", "video/x-amt-showrun" }, 562 | { ".xwd", "image/x-xwd" }, 563 | { ".z", "application/x-compressed" }, 564 | { ".zip", "application/zip" }, 565 | { ".zsh", "text/x-script.zsh" } 566 | }; 567 | 568 | public static string OctetStream => "application/octet-stream"; 569 | 570 | public static bool TryGetMimeType(string filename, 571 | #if NET481 572 | #else 573 | [NotNullWhen(true)] 574 | #endif 575 | 576 | out string? mimeType) 577 | { 578 | string? extension = Path.GetExtension(filename); 579 | 580 | return Extensions.TryGetValue(filename, out mimeType); 581 | } 582 | } 583 | } 584 | -------------------------------------------------------------------------------- /AnyWebApp/Utils/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Runtime.InteropServices; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AnyWebApp.Utils 9 | { 10 | public static class NativeMethods 11 | { 12 | public enum DwmWindowAttribute : uint 13 | { 14 | NCRenderingEnabled = 1, 15 | NCRenderingPolicy, 16 | TransitionsForceDisabled, 17 | AllowNCPaint, 18 | CaptionButtonBounds, 19 | NonClientRtlLayout, 20 | ForceIconicRepresentation, 21 | Flip3DPolicy, 22 | ExtendedFrameBounds, 23 | HasIconicBitmap, 24 | DisallowPeek, 25 | ExcludedFromPeek, 26 | Cloak, 27 | Cloaked, 28 | FreezeRepresentation, 29 | PassiveUpdateMode, 30 | UseHostBackdropBrush, 31 | UseImmersiveDarkMode = 20, 32 | WindowCornerPreference = 33, 33 | BorderColor, 34 | CaptionColor, 35 | TextColor, 36 | VisibleFrameBorderThickness, 37 | SystemBackdropType, 38 | Last 39 | } 40 | 41 | [DllImport("dwmapi.dll", PreserveSig = true)] 42 | public static extern int DwmSetWindowAttribute(nint hwnd, DwmWindowAttribute attr, ref int attrValue, int attrSize); 43 | 44 | public static bool EnableDarkModeForWindow(nint hWnd, bool enable) 45 | { 46 | int darkMode = enable ? 1 : 0; 47 | int hr = DwmSetWindowAttribute(hWnd, DwmWindowAttribute.UseImmersiveDarkMode, ref darkMode, sizeof(int)); 48 | return hr >= 0; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /AnyWebApp/Utils/SystemHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows; 7 | using Microsoft.Win32; 8 | 9 | namespace AnyWebApp.Utils 10 | { 11 | public static class SystemHelper 12 | { 13 | private static bool? IsDarkThemeDependOnRegistry() 14 | { 15 | const string RegistryKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize"; 16 | const string RegistryValueName = "AppsUseLightTheme"; 17 | // 这里也可能是LocalMachine(HKEY_LOCAL_MACHINE) 18 | // see "https://www.addictivetips.com/windows-tips/how-to-enable-the-dark-theme-in-windows-10/" 19 | object? registryValueObject = Registry.CurrentUser.OpenSubKey(RegistryKeyPath)?.GetValue(RegistryValueName); 20 | if (registryValueObject is null) 21 | return null; 22 | return (int)registryValueObject > 0 ? false : true; 23 | } 24 | 25 | public static bool IsDarkTheme() 26 | { 27 | return IsDarkThemeDependOnRegistry() ?? false; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /AnyWebApp/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 54 | 55 | 56 | 57 | true 58 | true 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /AnyWebApp/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/AnyWebApp/icon.ico -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 SlimeNull 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | ![icon](assets/icon256.png) 5 | 6 | # AnyWebApp 7 | 8 | _✨ Run any web app without hosting a web server! ✨_ 9 | 10 | [![ZH-HANS](https://img.shields.io/badge/中文-简体-red)](README.zh.md) 11 | [![LICENSE](https://img.shields.io/github/license/SlimeNull/AnyWebApp)](/LICENSE) 12 | ![GitHub all releases](https://img.shields.io/github/downloads/SlimeNull/AnyWebApp/total) 13 | 14 | 15 |
16 | 17 | --- 18 | 19 | You don't need to install anything, write any scripts, or do any complex configuration. 20 | Just follow these steps to run your web application as a desktop application on Windows. 21 | 22 | ## Preview 23 | 24 | This simple app was built with [vue](https://vuejs.org/) and [vuetify](https://vuetifyjs.com/), and it runs well on AnyWebApp 25 | 26 | ![preview](assets/preview1.png) 27 | 28 | 29 | ## Usage 30 | 31 | 1. Download the latest release. 32 | 2. Create a folder `wwwroot` for storage your web app assets. 33 | 3. Copy all of your web app assets to the folder 34 | 4. Start `AnyWebApp.exe` 35 | 36 | ## Requirements 37 | 38 | - [Microsoft Edge WebView2 Runtime](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) 39 | 40 | ## Confuguration 41 | 42 | After Starting `AnyWebApp.exe`, a config file named `AppConfig.json` will be generated. 43 | 44 | You can specify the root directory of the web application, 45 | the scheme used for requests, the default startup URI, 46 | the window title, icon, size, and scaling ratio, etc. in the configuration file. 47 | 48 | 49 | ## FAQ 50 | 51 | Below is the content about frequently asked questions and some usage tips. 52 | 53 | ### Configure for Vue Router 54 | 55 | If you are using Vue router and using 'history' mode, you can configure like this. 56 | 57 | 1. After Starting `AnyWebApp.exe`, a config file named `AppConfig.json` will be generated. 58 | 2. Open that config file, then set `EnableDocumentFallbackFiles` to `true` 59 | 60 | After completing these steps, when your program requests a non-existent document resource, 61 | it will return the document configured in the configuration file, such as `index.html`. 62 | This way, Vue Router can work in your web application. -------------------------------------------------------------------------------- /README.zh.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | ![icon](assets/icon256.png) 4 | 5 | # AnyWebApp 6 | 7 | _✨ 在没有托管 Web 服务器的情况下运行任何 Web 应用程序!✨_ 8 | 9 | 10 | [![LICENSE](https://img.shields.io/github/license/SlimeNull/AnyWebApp)](/LICENSE) 11 | [![GitHub all releases](https://img.shields.io/github/downloads/SlimeNull/AnyWebApp/total)](/Releases) 12 | 13 | 14 |
15 | 16 | --- 17 | 18 | 您无需安装任何东西、编写任何脚本或进行任何复杂的配置。只需按照以下步骤,在 Windows 上运行您的 Web 应用程序作为桌面应用程序。 19 | 20 | ## 预览 21 | 22 | 此简单的应用程序是使用 [vue](https://vuejs.org/) 和 [vuetify](https://vuetifyjs.com/) 构建的,并且在 AnyWebApp 上运行良好。 23 | 24 | ![preview](assets/preview1.png) 25 | 26 | 27 | ## 使用方法 28 | 29 | 1. 下载最新版本。 30 | 2. 创建一个名为 `wwwroot` 的文件夹,用于存储您的 Web 应用程序资产。 31 | 3. 将您的所有 Web 应用程序资产复制到该文件夹中。 32 | 4. 启动 `AnyWebApp.exe` 33 | 34 | ## 要求 35 | 36 | - [Microsoft Edge WebView2 Runtime](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) 37 | 38 | ## 配置 39 | 40 | 启动 `AnyWebApp.exe` 后,将生成一个名为 `AppConfig.json` 的配置文件。 41 | 42 | 您可以在配置文件中指定 Web 应用程序的根目录、请求所使用的方案、默认启动 URI、窗口标题、图标、大小和缩放比率等。 43 | 44 | ## 常见问题解答 45 | 46 | 以下是关于常见问题和一些使用技巧的内容。 47 | 48 | ### 配置 Vue Router 49 | 50 | 如果您正在使用 Vue Router 并使用“history”模式,则可以进行如下配置。 51 | 52 | 1. 启动 `AnyWebApp.exe` 后,将生成一个名为 `AppConfig.json` 的配置文件。 53 | 2. 打开该配置文件,然后将 `EnableDocumentFallbackFiles` 设置为 `true`。 54 | 55 | 完成这些步骤后,当您的程序请求不存在的文档资源时,它将返回在配置文件中配置的文档,例如 `index.html`。这样,Vue Router 就可以在您的 Web 应用程序中工作了。 -------------------------------------------------------------------------------- /assets/demo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 60 | 61 | 62 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /assets/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/assets/icon128.png -------------------------------------------------------------------------------- /assets/icon256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/assets/icon256.png -------------------------------------------------------------------------------- /assets/icon512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/assets/icon512.png -------------------------------------------------------------------------------- /assets/icon64.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/assets/icon64.png -------------------------------------------------------------------------------- /assets/preview1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SlimeNull/AnyWebApp/b35a8b695daa751acf4d4add134cf137dc51a75e/assets/preview1.png --------------------------------------------------------------------------------