From 85a25685d22e7bf81f70a5fd754458be23b0c7ab Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 29 Jan 2014 19:10:00 -0800 Subject: [PATCH] Changes to let Net45 sample run over Owin --- samples/MvcSample/Program.cs | 22 ++++++++++++++++++++++ samples/MvcSample/Startup.cs | 12 +++++++----- samples/MvcSample/project.json | 2 ++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 samples/MvcSample/Program.cs diff --git a/samples/MvcSample/Program.cs b/samples/MvcSample/Program.cs new file mode 100644 index 0000000000..40138e3b8e --- /dev/null +++ b/samples/MvcSample/Program.cs @@ -0,0 +1,22 @@ +#if NET45 +using System; +using Microsoft.Owin.Hosting; + +namespace MvcSample +{ + public class Program + { + const string baseUrl = "http://localhost:9001/"; + + public static void Main() + { + using (WebApp.Start(new StartOptions(baseUrl))) + { + Console.WriteLine("Listening at {0}", baseUrl); + Console.WriteLine("Press any key to exit"); + Console.ReadKey(); + } + } + } +} +#endif \ No newline at end of file diff --git a/samples/MvcSample/Startup.cs b/samples/MvcSample/Startup.cs index 3d3c67d167..020a7628ee 100644 --- a/samples/MvcSample/Startup.cs +++ b/samples/MvcSample/Startup.cs @@ -1,15 +1,12 @@ #if NET45 using System; -using System.Threading.Tasks; +using System.IO; using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Routing; -using Microsoft.Owin; using Microsoft.Owin.FileSystems; using Owin; -[assembly: OwinStartup(typeof(MvcSample.Startup))] - namespace MvcSample { public class Startup @@ -20,7 +17,12 @@ namespace MvcSample var serviceProvider = MvcServices.Create(); - string appRoot = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; + // HACK to determine app root. + string appRoot = Environment.CurrentDirectory; + while (!String.IsNullOrEmpty(appRoot) && !appRoot.TrimEnd(Path.DirectorySeparatorChar).EndsWith("MvcSample")) + { + appRoot = Path.GetDirectoryName(appRoot); + } serviceProvider.AddInstance(new PhysicalFileSystem(appRoot)); serviceProvider.Add(); diff --git a/samples/MvcSample/project.json b/samples/MvcSample/project.json index fb7b9d8012..2923551b4a 100644 --- a/samples/MvcSample/project.json +++ b/samples/MvcSample/project.json @@ -15,6 +15,8 @@ "Owin": "1.0", "Microsoft.Owin": "2.1.0", "Microsoft.Owin.Diagnostics": "2.1.0", + "Microsoft.Owin.Hosting": "2.1.0", + "Microsoft.Owin.Host.HttpListener": "2.1.0", "Microsoft.AspNet.Abstractions.Owin": "0.1-alpha-*" } },