azure - 在 Azure Web Apps 中运行自托管 OWIN 应用程序

标签 azure owin azure-web-app-service kudu suave

It is possible运行 suave.io应用程序 Azure Web Apps因为 IIS8 的一项名为 HttpPlatformHandler 的功能。我尝试以相同的方式运行自托管 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来监听正确的端口。我的网络应用程序按如下方式启动服务器:

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 存储库发布了该应用程序。

为什么我无法使用 OWIN 打开端口?与 suave.io 示例有何不同?

编辑: 我刚刚看到有一个请求支持这个确切的场景:https://feedback.azure.com/forums/169385-web-apps-formerly-websites/suggestions/4606121-support-owin-self-hosting-in-azure-websites

最佳答案

我也遇到了同样的问题。只需以管理员身份运行 Visual Studio 即可解决。

(您可能还需要重新启动 Azure 模拟器)

关于azure - 在 Azure Web Apps 中运行自托管 OWIN 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29936226/

相关文章:

azure - 使用 Azure Function 处理 Azure 存储队列后删除消息

azure - 从我的 ASP.NET 网站执行按需 Web 作业?

asp.net - 使用 OWIN oAuth 中间件(具有单独的身份验证和资源服务器)时,我收到 "Authorization has been denied for this request."错误消息

asp.net - 在 Web api IExceptionHandler 中获取请求正文

azure - 是否可以使用 Powershell 更新 Azure AD 中现有用户的 SignInNames

azure - 工作帐户和 Microsoft 帐户之间的混淆

c# - 如果我使用 OWIN Startup.cs 类并将所有配置移到那里,我是否需要 Global.asax.cs 文件?

azure - 无法让应用服务 CDN 与身份验证一起使用

azure - 将 Azure SDK 和 Azure 存储版本升级到最新版本

powershell - Azure WebApp - 如何使用 Powershell 或 API 重新启动单个实例