Created
August 19, 2014 08:08
-
-
Save mikaelbr/4da3be29d64d78b5d7ea to your computer and use it in GitHub Desktop.
OWIN test for hosting static files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using Microsoft.Owin.Hosting; | |
using Microsoft.Owin.FileSystems; | |
using Microsoft.Owin.StaticFiles; | |
using Owin; | |
namespace Test.Owin.StaticFiles | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var url = "http://localhost:8080"; | |
WebApp.Start<Startup>(url); | |
Console.WriteLine("Listening at " + url); | |
Console.ReadLine(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Owin; | |
using Microsoft.Owin.FileSystems; | |
using Microsoft.Owin.StaticFiles; | |
using Owin; | |
using System.IO; | |
using System.Reflection; | |
using System; | |
namespace Test.Owin.StaticFiles | |
{ | |
public class Startup | |
{ | |
public void Configuration(IAppBuilder app) | |
{ | |
var relativePath = string.Format (@"..{0}..{0}", Path.DirectorySeparatorChar); | |
string contentPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), relativePath); | |
#if DEBUG | |
app.UseErrorPage(); | |
#endif | |
app.UseFileServer(new FileServerOptions() | |
{ | |
RequestPath = PathString.Empty, | |
FileSystem = new PhysicalFileSystem(Path.Combine(contentPath, @"public")), | |
}); | |
app.UseStaticFiles (new StaticFileOptions () | |
{ | |
RequestPath = new PathString ("/assets"), | |
FileSystem = new PhysicalFileSystem (Path.Combine(contentPath, @"assets")) | |
}); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment