2015-04-29 16 views
15

It is possible để chạy ứng dụng suave.io trên Azure Web Apps vì tính năng IIS8 được gọi là HttpPlatformHandler. Tôi đã cố gắng chạy một ứng dụng OWIN tự lưu trữ theo cùng một cách, nhưng có ngoại lệ khi khởi động:Chạy ứng dụng OWIN tự lưu trữ trong Ứng dụng web Azure

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 

Dường như tôi không được phép mở cổng. web.config của tôi trông như thế này:

<?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> 

tôi sử dụng HTTP_PLATFORM_PORT để lắng nghe trên cổng bên phải. ứng dụng web của tôi bắt đầu máy chủ như sau:

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 có vẻ là OK vì tôi nhận được kết quả như thế này: Starting web app at http://127.0.0.1:32880.

Web.config và tất cả các tệp nhị phân nằm trong thư mục gốc và tôi đã xuất bản ứng dụng bằng cách sử dụng repo git cục bộ.

Tại sao tôi không thể mở cổng bằng OWIN? Có gì khác với mẫu suave.io?

EDIT: Tôi chỉ thấy có một yêu cầu để hỗ trợ kịch bản chính xác này: https://feedback.azure.com/forums/169385-web-apps-formerly-websites/suggestions/4606121-support-owin-self-hosting-in-azure-websites

+0

Có thể là im lặng tại đây vì // Hội thảo xây dựng. Tôi sẽ kiên nhẫn thêm vài ngày nữa :-) –

+0

Bạn đã bao giờ tìm được câu trả lời cho điều này chưa? Tôi đang triển khai khá một vài ứng dụng và dịch vụ F # ​​bằng cách sử dụng thủ thuật HttpPlatformHandler, nhưng tôi đang cố gắng để bắt đầu và chạy với một máy chủ signalr sử dụng OWIN và F # và không có gì là 'chỉ hoạt động'. – tigerswithguitars

+0

Chúng tôi chưa bao giờ thử lại. Ứng dụng hiện đang chạy trong vai trò của nhân viên. –

Trả lời

5

I Had cùng một vấn đề. Giải quyết đơn giản bằng cách chạy Visual Studio với tư cách Quản trị viên.

(Bạn có thể cần phải khởi động lại Trình giả lập Azure)

+1

Tôi không thử chạy ứng dụng trong trình mô phỏng. Tôi triển khai nó trực tiếp đến Azure. –

+0

Bro - bạn vừa mới cứu mạng tôi. –

Các vấn đề liên quan