VS 2015 +所有更新。 添加了一个带有认证的ASP .Net项目(身份) 目标 - 将项目分层。
层:
DataAccess (所有数据库表,模型等)
BusinessLogic (CRUD操作)
Web类库(所以我不需要绑DA和BL我添加了一个额外的层来执行此操作)
ASP .Net Web应用程序
课堂和项目中的代码:
using Microsoft.Owin;
using Owin;
using Company.Web;
[assembly: OwinStartupAttribute(typeof(Startup))]
namespace Company.Web
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
}
}
Startup.Auth
中的代码namespace Company.Web
{
public partial class Startup
{
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context, user manager and signin manager to use a single instance per request
我收到错误
抑制状态错误CS0103名称' ConfigureAuth'在当前上下文WebApplication1
中不存在我在“Startup'带着友好的信息:
[assembly:OwinStartupAttribute(typeof(Startup))]
类型'初创公司'在' .... WebApplication1 \ Startup.cs'与导入类型的冲突' Startup' in' Company.Web,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'。使用' .... WebApplication1 \ Startup.cs'中定义的类型。
错误
CS0103名称' ConfigureAuth'在当前上下文WebApplication1 .... WebApplication1 \ Startup.cs
中不存在所以我研究了一些链接,例如
the name configureauth does not exist The name 'ConfigureAuth' does not exist in the current contex ASP.NET MVC OWIN and SignalR - two Startup.cs files
但是,如果我对这个项目的结构方式不正确或者我错过了一些明显的东西,那就无法解决问题了吗?
答案 0 :(得分:1)
如果您使用的是默认的Visual Studio项目模板,则可以在部分类Startup.Auth.cs中找到ConfigureAuth方法。因此,在修改项目结构时,请确保没有破坏任何内容。
这是ConfigureAuth方法的一个示例:
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864
public void ConfigureAuth(IAppBuilder app)
{
// Configure the db context and user manager to use a single instance per request
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
// Enable the application to use a cookie to store information for the signed in user
// and to use a cookie to temporarily store information about a user logging in with a third party login provider
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
// Configure the application for OAuth based flow
PublicClientId = "self";
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/api/Token"),
Provider = new ApplicationOAuthProvider(PublicClientId),
AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}