在azure web应用程序中运行自托管的owin应用程序

m2xkgtsf  于 2021-06-20  发布在  Kudu
关注(0)|答案(1)|浏览(584)

可以在azure web应用程序上运行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, Object[] parameters, 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 听正确的端口。我的web应用程序按如下方式启动服务器:

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似乎正常,因为我得到如下输出: Starting web app at 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

cld4siwp

cld4siwp1#

我也有同样的问题。只需以管理员身份运行visualstudio即可解决。
(您可能还需要重新启动azure emulator)

相关问题