-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from arichika/feature/forVS2017Update&Refactoring
Feature/for vs2017 update&refactoring
- Loading branch information
Showing
47 changed files
with
261 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -292,4 +292,5 @@ __pycache__/ | |
*.btp.cs | ||
*.btm.cs | ||
*.odx.cs | ||
*.xsd.cs | ||
*.xsd.cs | ||
/Src/SampleWebSite/MyConnectionStrings.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
|
||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.