开始申请

时间:2016-01-30 14:50:17

标签: c# asp.net asp.net-mvc

我已按照教程tutorial进行操作。我已经读过在我的web应用程序中要执行的第一个文件是startup.cs,但startup.cs只包含以下代码。执行此文件后发生了哪些步骤?我没有看到任何页面打开...谢谢!

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(ContactManager.Startup))]
namespace ContactManager
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

Index.cshtml页面:

@{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
    <h1>ASP.NET</h1>
    <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
    <p><a href="http://asp.net" class="btn btn-primary btn-lg">Learn more &raquo;</a></p>
</div>

<div class="row">
    <div class="col-md-4">
        <h2>Getting started</h2>
        <p>
            ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that
            enables a clean separation of concerns and gives you full control over markup
            for enjoyable, agile development.
        </p>
        <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
    </div>
    <div class="col-md-4">
        <h2>Get more libraries</h2>
        <p>NuGet is a free Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects.</p>
        <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301866">Learn more &raquo;</a></p>
    </div>
    <div class="col-md-4">
        <h2>Web Hosting</h2>
        <p>You can easily find a web hosting company that offers the right mix of features and price for your applications.</p>
        <p><a class="btn btn-default" href="http://go.microsoft.com/fwlink/?LinkId=301867">Learn more &raquo;</a></p>
    </div>
</div>

1 个答案:

答案 0 :(得分:2)

Startup.cs将通过设置各种服务来初始化您的项目。在这种情况下,它设置身份验证框架。位于Startup.cs的代码只运行一次,这是IIS第一次启动您的网站时。它不会为每个后续请求运行。

当您尝试打开页面时,您的浏览器发出HTTP GET请求,然后由MVC路由管理系统拦截和处理。尝试找到您的路由配置(可能在名为RouteConfig.cs的文件中)。您的路由配置将指示默认情况下将加载哪个视图。

例如;以下路线告诉我,我的默认视图将是Index

HomeController.cs方法生成的内容
routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

希望这有帮助