My first .net Owin program does not start and shows a web page

I followed this example to create my first Owin web page:

  • Start VS2013 , C #, create a project for a Web application: WebApplication1.
  • ToolsPackage Manager NugetPackage Manager Console

    PM> Install-Package microsoft.owin.host.SystemWeb

Now I can see the owin link. 3. AddNew itemOwin launch class and enter the code snippet:

    using System;
    using System.Threading.Tasks;
    using Microsoft.Owin;
    using Owin;

    [assembly: OwinStartup(typeof(WebApplication1.Startup1))]

    namespace WebApplication1
    {
            public class Startup1
            {
                    public void Configuration(IAppBuilder app)
                    {
                            // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
                            app.Run(context =>
                            {
                                    context.Response.ContentType = "text/plain";
                                    return context.Response.WriteAsync("Hello, world.");
                            });
                    }
            }
    }

OK, now I start Ctrl + F5 and it calls IE browser. Unfortunately, the page displays some error inside the web application:

HTTP Error 403.14 - Forbidden

The web server is configured to not display the contents of this directory.

, :         • URL-, .

:         • , , .         • . 1. IIS Express.         2.Run appcmd set config/section:system.webServer/directoryBrowse/enabled: true, .         3.Run appcmd set config [ "SITE_NAME" ]/section:system.webServer/directoryBrowse/enabled: true, .

• , configuration/system.webServer/directoryBrowse@enabled true .

:

   DirectoryListingModule

Notification            ExecuteRequestHandler

Handler            StaticFile

           0x00000000

URL            http://localhost:50598/

           D:\Documents\Visual Studio 2013\Projects\WebApplication1

    

    D:\Documents\IISExpress\TraceLogFiles\WEBAPPLICATION1

:    , URL-, - , - . .          "

, -, ? ?

+4
1

. . , - . , . , , .

  • > > >
  • -
  • Microsoft.Owin.Host.SystemWeb: PM> install-package microsoft.owin.host.systemweb

  • > > Startup.cs

  • owin

:

using Owin;

namespace WebApplication2
{
    public class Startup
    {
        public static void Configuration(IAppBuilder app)
        {
            app.Use(async (ctx, next) =>
            {
                await ctx.Response.WriteAsync("Test");
            });
        }
    }
}

, , package.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
  <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
  <package id="Microsoft.Owin" version="3.0.1" targetFramework="net452" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.1" targetFramework="net452" />
  <package id="Owin" version="1.0" targetFramework="net452" />
</packages>

.. web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2"/>
    <httpRuntime targetFramework="4.5.2"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
</configuration>

. , . , , .

+2

Source: https://habr.com/ru/post/1649860/


All Articles