- Create an empty web application project
- Install OWIN using NuGet (
install-package Microsoft.Owin.Host.SystemWeb ) - Add an empty class to the root directory of the project "Startup.cs"
Here I will answer your third question. The launch class is the OWIN entry point and is automatically scanned. As stated in the official docs:
Naming Convention: Katana looks for a class named Startup in the namespace by matching the assembly name or global namespace.
Note that you can also choose your own Startup class name, but you must set it using decorators or AppConfig. As stated here: https://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection
This is all you need for the basic and working OWIN test:
using Owin; using System; namespace OwinTest { public class Startup { public static void Configuration(IAppBuilder app) { app.Use(async (ctx, next) => { await ctx.Response.WriteAsync(DateTime.Now.ToString() + " My First OWIN App"); }); } } }
If you want to use MVC (I assume that "Home / Index" means MVC), follow these steps:
- Install MVC NuGet (
install-package Microsoft.AspNet.Mvc ). - Add the Controllers folder to the project.
- Create a new empty controller in the new "Controlles" folder (right-click → add → MVC 5 Controller - Empty) and name it "HomeController".
- Create a view page in the newly created Views / Home folder. Right click → Add → View. Name it "Index" and uncheck "Use this page for customs."
Make the page inherited from WebViewPage. Everything should look like this:
@inherits System.Web.Mvc.WebViewPage @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Index</title> </head> <body> <div> <h1>Owin Hello</h1> </div> </body> </html>
- Add
global.asax to configure routes. Right click on the project -> Add -> New Item -> Global Application Class.
Add route definition to Application_Start method:
protected void Application_Start(object sender, EventArgs e) { RouteTable.Routes.MapRoute(name: "Default", url: "{controller}/{action}", defaults: new { controller = "Home", action = "Index" }); }
- Be sure to comment on the previous middleware "..await ctx.Response.WriteAsync ...". Otherwise, it will interfere with MVC.
- Run the project. Must work.
source share