It is possible在 Azure Web Apps上运行一个 suave.io应用程序,因为一个名为 HttpPlatformHandler的IIS8功能.我尝试以相同的方式运行一个自我托管的OWIN应用程序,但启动时出现异常:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Net.HttpListenerException: Access is denied at System.Net.HttpListener.SetupV2Config() at System.Net.HttpListener.Start() at Microsoft.Owin.Host.HttpListener.OwinHttpListener.Start(HttpListener listener,Func`2 appFunc,IList`1 addresses,IDictionary`2 capabilities,Func`2 loggerFactory) at Microsoft.Owin.Host.HttpListener.OwinServerFactory.Create(Func`2 app,IDictionary`2 properties) --- End of inner exception stack trace --- at System.RuntimeMethodHandle.InvokeMethod(Object target,Object[] arguments,Signature sig,Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object[] parameters,Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,CultureInfo culture) at Microsoft.Owin.Hosting.ServerFactory.ServerFactoryAdapter.Create(IAppBuilder builder) at Microsoft.Owin.Hosting.Engine.HostingEngine.StartServer(StartContext context) at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context) at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services,StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start[TStartup](String url) at WebAppSample.Program.Main(String[] args) in c:\Users\egger\Workspace\WebAppSample\WebAppSample\Program.cs:line 14
看来我不允许开一个港口.我的web.config看起来像这样:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <handlers> <remove name="httpplatformhandler" /> <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /> </handlers> <httpPlatform stdoutLogEnabled="true" stdoutLogFile="site.log" startupTimeLimit="20" processPath="%HOME%\site\wwwroot\WebAppSample.exe" arguments="%HTTP_PLATFORM_PORT%"> </httpPlatform> </system.webServer> </configuration>
我使用HTTP_PLATFORM_PORT来侦听正确的端口.我的网络应用程序启动服务器如下:
class Program { static void Main(string[] args) { var port = int.Parse(args[0]); var url = string.Format("http://127.0.0.1:{0}",port); Console.WriteLine("Starting web app at {0}",url); using (WebApp.Start<Startup>(url)) { Console.ReadLine(); } } } public class Startup { public void Configuration(IAppBuilder app) { app.UseErrorPage(); app.UseWelcomePage("/"); } }
该URL似乎是好的,因为我得到如下输出:启动Web应用程序http://127.0.0.1:32880.
web.config和所有二进制文件都在根目录下,我使用本地的git repo发布了该应用程序.
为什么不能使用OWIN打开端口?与suave.io样本有什么不同?
编辑:
我刚刚看到有一个要求来支持这个确切的情况:https://feedback.azure.com/forums/169385-web-apps-formerly-websites/suggestions/4606121-support-owin-self-hosting-in-azure-websites