4
votes

I followed this example to create my 1st Owin web page:

  1. Start VS2013, create C# project of Web application: WebApplication1.
  2. Tools->Nuget package manager->package manager console

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

I can now see the owin reference. 3. Add->New Item->Owin startup class and enter 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 Ctrl+F5 to start, and it brings up an IE browser. Unluckily, the page shows there's some error inside the web application:

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.

Most likely causes: •A default document is not configured for the requested URL, and directory browsing is not enabled on the server.

Things you can try: •If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists. • Enable directory browsing. 1.Go to the IIS Express install directory. 2.Run appcmd set config /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the server level. 3.Run appcmd set config ["SITE_NAME"] /section:system.webServer/directoryBrowse /enabled:true to enable directory browsing at the site level.

•Verify that the configuration/system.webServer/directoryBrowse@enabled attribute is set to true in the site or application configuration file.

Detailed Error Information:

Module DirectoryListingModule

Notification ExecuteRequestHandler

Handler StaticFile

Error Code 0x00000000

Requested URL http://localhost:50598/

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

Anonymous

Logon User Anonymous

Request Tracing Directory D:\Documents\IISExpress\TraceLogFiles\WEBAPPLICATION1

More Information: This error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server. View more information »

So is there anything I missed or wrongly committed in all my steps? How to make it work?

1
Have you installed ASP.NET? Windows Features -> Internet Information Services -> World Wide Web Services -> Application Development Features -> ASP.NET x.x.RB.

1 Answers

3
votes

Your example works fine for me. I couldn't reproduce your error. Seems like something is misconfigured. Perhaps try to check some of the existing answers here and here. I'm including my steps which works perfectly fine for me so you can double check your solution.

  1. File > New > Project > Web
  2. Create completely empty web application
  3. Install Microsoft.Owin.Host.SystemWeb package: PM> install-package microsoft.owin.host.systemweb

  4. Right click on project in solution explorer > Add > Class and name it Startup.cs

  5. Insert your owin middleware

This is how my class looks like:

using Owin;

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

Just to make sure, I'm also including my packages.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>

..and 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>

I have done absolutely nothing else. These are the only steps I've taken. You can compare and perhaps come up with differences.