Skip to content

Commit

Permalink
Merge pull request #12 from arichika/feature/forVS2017Update&Refactoring
Browse files Browse the repository at this point in the history
Feature/for vs2017 update&refactoring
  • Loading branch information
arichika authored Jul 28, 2017
2 parents 1d19006 + 66bc10e commit fd7391a
Show file tree
Hide file tree
Showing 47 changed files with 261 additions and 248 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,5 @@ __pycache__/
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
*.xsd.cs
/Src/SampleWebSite/MyConnectionStrings.config
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@ This is an example to implement a OracleDatabase store for ASP.NET Identity 2.0

Steps to run project

- Open project in VS with Update 2 or later installed
- Open project in Latest Visual Studio 2017 or later installed
- Build project to restore packages and build project
- In the solution, add a new one ASP.NET project with MVC and Individual Authentication
- Uninstall Microsoft.AspNet.Identity.EntityFramework package from the web application
- Update connection string to use the OracleDatabase database as needed
- Make the file "MyConnectionStrings.config" into the project SampleWebSite's root folder
- e.g.
```
- Make the file `MyConnectionStrings.config` into the project SampleWebSite's root folder
- e.g.
```
<?xml version="1.0" encoding="utf-8"?>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=OracleDbTnsName; User Id=scott;Password=tiger;"
providerName="Oracle.DataAccess.Client" />
</connectionStrings>
```
```
- In the IdentityModel.cs (in the SampleWebProject),
let ApplicationUser class extend from Identity user in AspNet.Identity.Oracle
- e.g
```
- e.g
```
using AspNet.Identity.Oracle;
// using Microsoft.AspNet.Identity.EntityFramework;
```
```
- ApplicationDbContext extend from OracleDatabase and the contructor take a single parameter with the connectionstring name
```
public class ApplicationDbContext : OracleDatabase
Expand All @@ -61,18 +61,17 @@ var manager = new ApplicationRoleManager(new RoleStore<IdentityRole>(context.Get
you can write some code block at the InitializeDb method or InitializeIdentity method
in the ApplicationDbInitializer class (in the IdentityConfig.cs)
- This SampleWebSite project enabled initial admin account as shoen below
```
```
const string name = "[email protected]";
const string password = "Admin@123456";
const string roleName = "Admin";
```
```
- Before you do debugging, you must create the tables in the database.
Please run DDL Script, "OracleIdentity.sql.txt" in the AspNet.Identity.Oracle project.
Please run DDL Script, `OracleIdentity.sql.txt` in the AspNet.Identity.Oracle project.

- If you have an error appears at the start of debugging, please try the following below.
- To start the Visual Studio by "Run as Administrator".
- Debugging on the "Local IIS" not "IIS Express".
- Check build platform Win32 or x64, this project and installed ODP.NET.
- Debugging on the `IIS Express`.
- Check build platform Win32 or x64, this project and installed ODP.NET. (means Not Oracle.ManagedAccess)


Notice
Expand Down
4 changes: 2 additions & 2 deletions Src/AspNet.Identity.Oracle/AspNet.Identity.Oracle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNet.Identity.Core">
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
<Reference Include="Microsoft.AspNet.Identity.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.2.2.1\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
</Reference>
<Reference Include="Oracle.DataAccess, Version=4.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
Expand Down
4 changes: 2 additions & 2 deletions Src/AspNet.Identity.Oracle/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("1.0.3.0")]
28 changes: 13 additions & 15 deletions Src/AspNet.Identity.Oracle/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

Steps to run project

- Open project in VS with Update 2 or later installed
- Open project in Latest Visual Studio 2017 or later installed
- Build project to restore packages and build project
- In the solution, add a new one ASP.NET project with MVC and Individual Authentication
- Uninstall Microsoft.AspNet.Identity.EntityFramework package from the web application
- Update connection string to use the OracleDatabase database as needed
- Make the file "MyConnectionStrings.config" into the project SampleWebSite's root folder
- e.g.
```
- Make the file `MyConnectionStrings.config` into the project SampleWebSite's root folder
- e.g.
```
<?xml version="1.0" encoding="utf-8"?>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Data Source=OracleDbTnsName; User Id=scott;Password=tiger;"
providerName="Oracle.DataAccess.Client" />
</connectionStrings>
```
```
- In the IdentityModel.cs (in the SampleWebProject),
let ApplicationUser class extend from Identity user in AspNet.Identity.Oracle
- e.g
```
- e.g
```
using AspNet.Identity.Oracle;
// using Microsoft.AspNet.Identity.EntityFramework;
```
```
- ApplicationDbContext extend from OracleDatabase and the contructor take a single parameter with the connectionstring name
```
public class ApplicationDbContext : OracleDatabase
Expand All @@ -47,17 +47,15 @@ var manager = new ApplicationRoleManager(new RoleStore<IdentityRole>(context.Get
you can write some code block at the InitializeDb method or InitializeIdentity method
in the ApplicationDbInitializer class (in the IdentityConfig.cs)
- This SampleWebSite project enabled initial admin account as shoen below
```
```
const string name = "[email protected]";
const string password = "Admin@123456";
const string roleName = "Admin";
```
```
- Before you do debugging, you must create the tables in the database.
Please run DDL Script, "OracleIdentity.sql.txt" in the AspNet.Identity.Oracle project.
Please run DDL Script, `OracleIdentity.sql.txt` in the AspNet.Identity.Oracle project.

- If you have an error appears at the start of debugging, please try the following below.
- To start the Visual Studio by "Run as Administrator".
- Debugging on the "Local IIS" not "IIS Express".
- Check build platform Win32 or x64, this project and installed ODP.NET.
- Debugging on the `IIS Express`.
- Check build platform Win32 or x64, this project and installed ODP.NET. (means Not Oracle.ManagedAccess)

//
2 changes: 1 addition & 1 deletion Src/AspNet.Identity.Oracle/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.AspNet.Identity.Core" version="2.0.1" targetFramework="net45" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.1" targetFramework="net45" />
</packages>
2 changes: 1 addition & 1 deletion Src/SampleWebSite/App_Start/BundleConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Web.Optimization;

namespace IdentitySample
namespace SampleWebSite
{
public class BundleConfig
{
Expand Down
2 changes: 1 addition & 1 deletion Src/SampleWebSite/App_Start/FilterConfig.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Web.Mvc;

namespace IdentitySample
namespace SampleWebSite
{
public class FilterConfig
{
Expand Down
104 changes: 2 additions & 102 deletions Src/SampleWebSite/App_Start/IdentityConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
using System.Threading.Tasks;
using System.Web;
using AspNet.Identity.Oracle;
using SampleWebSite.Models;

namespace IdentitySample.Models
namespace SampleWebSite
{
// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
public class ApplicationUserManager : UserManager<ApplicationUser>
Expand Down Expand Up @@ -156,107 +157,6 @@ public Task SendAsync(IdentityMessage message)
}
}


//This is useful if you do not want to tear down the database each time you run the application.
public sealed class ApplicationDbInitializer : IDisposable
{
private static readonly object ThisLock = new object();
private static volatile ApplicationDbInitializer _applicationDbInitializer;

private bool _isInitialized;

private ApplicationDbInitializer(IOwinContext context)
{
Seed(context);
}

public static ApplicationDbInitializer Create(IdentityFactoryOptions<ApplicationDbInitializer> options, IOwinContext context)
{
if (_applicationDbInitializer != null)
return _applicationDbInitializer;

lock (ThisLock)
{
if (_applicationDbInitializer != null) return _applicationDbInitializer;
_applicationDbInitializer = new ApplicationDbInitializer(context);
}
return _applicationDbInitializer;
}

/// <summary>
/// Run Once Initialize code blocks.
/// </summary>
/// <param name="context"></param>
private void Seed(IOwinContext context)
{
if (_isInitialized) return;

InitializeDb(context);
InitializeIdentity(context);

_isInitialized = true;
}

// Verify Db or Tables and Create it, If you need.
private static void InitializeDb(IOwinContext context)
{
// var oracleDatabase = context.Get<ApplicationDbContext>() as OracleDatabase;
// e.g. Run the DDL if Table is not.
}

// Create Sample Admin User: [email protected] with password: Admin@123456 in the Admin role
private static void InitializeIdentity(IOwinContext context)
{
var userManager = context.GetUserManager<ApplicationUserManager>();
var roleManager = context.Get<ApplicationRoleManager>();

const string name = "[email protected]";
const string password = "Admin@123456";
const string roleName = "Admin";

//Create Role Admin if it does not exist
var role = roleManager.FindByName(roleName);
if (role == null) {
role = new IdentityRole(roleName);
var roleresult = roleManager.Create(role);
}

var user = userManager.FindByName(name);
if (user == null) {
user = new ApplicationUser { UserName = name, Email = name };
var result = userManager.Create(user, password);
result = userManager.SetLockoutEnabled(user.Id, false);
}

// Add user admin to Role Admin if not already added
var rolesForUser = userManager.GetRoles(user.Id);
if (!rolesForUser.Contains(role.Name)) {
var result = userManager.AddToRole(user.Id, role.Name);
}
}

bool _disposed;

public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

private void Dispose(bool disposing)
{
if (_disposed) return;

if (disposing)
{
// Free any other managed objects here.
}

// Free any unmanaged objects here.
_disposed = true;
}
}

public enum SignInStatus
{
Success,
Expand Down
2 changes: 1 addition & 1 deletion Src/SampleWebSite/App_Start/RouteConfig.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Web.Mvc;
using System.Web.Routing;

namespace IdentitySample {
namespace SampleWebSite {
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Expand Down
Loading

0 comments on commit fd7391a

Please sign in to comment.