Computer
Computer

Reputation: 2227

The name 'ConfigureAuth' does not exist

VS 2015 + all updates. Added an ASP .Net project with authetication (Identity) Aim - to separate the project into layers.

Layers:

DataAccess (All database tables, models etc)

BusinessLogic (CRUD operations)

Web Class Library (So i dont need to tie the DA and BL i added an extra layer to do this)

ASP .Net Web Application

  1. Move Models Folder into DA.
  2. Move IdentityConfig.cs into root of DA.
  3. Add all references required to DA, change namespaces accordingly. Project builds succesfully.
  4. Move Controller folder into BL.
  5. Add all references required to BL, change namespaces accordingly. Project builds succesfully.
  6. Move BundleConfig, FilterConfig, RouteConfig and Startup.Auth to the root of the Web Class library.
  7. Add all references required to the web library. Project builds succesfully.
  8. In the Web application i change the Startup and

Code in class and project:

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);
        }
    }
}

Code in 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

I get the error

Suppression State Error CS0103 The name 'ConfigureAuth' does not exist in the current context WebApplication1

I have a squiggle on 'Startup' with a friendly message:

[assembly: OwinStartupAttribute(typeof(Startup))]

The type 'Startup' in '....WebApplication1\Startup.cs' conflicts with the imported type 'Startup' in 'Company.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '....WebApplication1\Startup.cs'.

The error

CS0103 The name 'ConfigureAuth' does not exist in the current context WebApplication1 ....WebApplication1\Startup.cs

So i researched around and seen a few links e.g

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

But cant work out if the way i have structered this project is incorrect or if im missing something obvious?

Upvotes: 0

Views: 4184

Answers (1)

Husni Salax
Husni Salax

Reputation: 2020

If you are using default Visual Studio project template, the ConfigureAuth method could be found in partial class Startup.Auth.cs. So make sure you didn't break anything when modifying project structure.

This is an example of ConfigureAuth method:

// 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);
}

Upvotes: 1

Related Questions