gpt4 book ai didi

c# - asp.net 5.0 preview - web api template - 为什么没有认证

转载 作者:太空狗 更新时间:2023-10-29 23:21:50 27 4
gpt4 key购买 nike

我已经在新的 Visual Studio 2015 中创建了一个 Web 项目。

我可以选择 asp.net 4.6 或 5.0 预览版 web api 模板。老4.6有

身份验证,但我想使用新的 5.0 预览版和 web api。

但是这个模板没有认证,为什么?

最佳答案

在 OWIN 世界中,您可以在需要时提供所需的身份验证。这是 ASP.NET 5 世界的新范例。 “你只会得到你明确表示需要的东西。如果你不要求,你就得不到”。这只是这种心态的另一个例子。

Scott Guthrie 在他最近的 post 中指出了这一点:

ASP.NET 5 introduces a new HTTP request pipeline that is modular soyou can add only the components that you need. The pipeline is also nolonger dependent on System.Web. By reducing the overhead in thepipeline, your app can experience better throughput and a more tunedHTTP stack. The new pipeline is based on many of the learnings fromthe Katana project and also supports OWIN.

To customize which components are used in the pipeline, use theConfigure method in your Startup class. The Configure method is usedto specify which middleware you want to “use” in your requestpipeline. ASP.NET 5 already includes ported versions of many of themiddleware from the Katana project, like middleware for static files,authentication and diagnostics. The following image shows some of thefeatures you can add or remove to the pipeline for your project.

您可以非常快速地插入您的安全;您只需要指定您将使用的是什么。

public void Configure(IApplicationBuilder app)
{
// Add static files to the request pipeline.
app.UseStaticFiles();

// Add cookie-based authentication to the request pipeline.
app.UseIdentity();

// Add MVC and routing to the request pipeline.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });

});

关于c# - asp.net 5.0 preview - web api template - 为什么没有认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30200862/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com