-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for ASP.NET and included a demo.
- Loading branch information
Showing
95 changed files
with
33,980 additions
and
2 deletions.
There are no files selected for viewing
1,070 changes: 1,070 additions & 0 deletions
1,070
Samples/net46/CSharp/AspNetSamples/.vs/config/applicationhost.config
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.24720.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MvcDemo", "MvcDemo\MvcDemo.csproj", "{096E2905-36BE-4CA3-A5B9-94870522D447}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{096E2905-36BE-4CA3-A5B9-94870522D447}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{096E2905-36BE-4CA3-A5B9-94870522D447}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{096E2905-36BE-4CA3-A5B9-94870522D447}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{096E2905-36BE-4CA3-A5B9-94870522D447}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
31 changes: 31 additions & 0 deletions
31
Samples/net46/CSharp/AspNetSamples/MvcDemo/App_Start/BundleConfig.cs
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Web; | ||
using System.Web.Optimization; | ||
|
||
namespace MvcDemo | ||
{ | ||
public class BundleConfig | ||
{ | ||
// For more information on bundling, visit http://go.microsoft.com/fwlink/?LinkId=301862 | ||
public static void RegisterBundles(BundleCollection bundles) | ||
{ | ||
bundles.Add(new ScriptBundle("~/bundles/jquery").Include( | ||
"~/Scripts/jquery-{version}.js")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( | ||
"~/Scripts/jquery.validate*")); | ||
|
||
// Use the development version of Modernizr to develop with and learn from. Then, when you're | ||
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need. | ||
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( | ||
"~/Scripts/modernizr-*")); | ||
|
||
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( | ||
"~/Scripts/bootstrap.js", | ||
"~/Scripts/respond.js")); | ||
|
||
bundles.Add(new StyleBundle("~/Content/css").Include( | ||
"~/Content/bootstrap.css", | ||
"~/Content/site.css")); | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Samples/net46/CSharp/AspNetSamples/MvcDemo/App_Start/FilterConfig.cs
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace MvcDemo | ||
{ | ||
public class FilterConfig | ||
{ | ||
public static void RegisterGlobalFilters(GlobalFilterCollection filters) | ||
{ | ||
filters.Add(new HandleErrorAttribute()); | ||
} | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
Samples/net46/CSharp/AspNetSamples/MvcDemo/App_Start/IdentityConfig.cs
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.Entity; | ||
using System.Linq; | ||
using System.Security.Claims; | ||
using System.Threading.Tasks; | ||
using System.Web; | ||
using Microsoft.AspNet.Identity; | ||
using Microsoft.AspNet.Identity.EntityFramework; | ||
using Microsoft.AspNet.Identity.Owin; | ||
using Microsoft.Owin; | ||
using Microsoft.Owin.Security; | ||
using MvcDemo.Models; | ||
|
||
namespace MvcDemo | ||
{ | ||
public class EmailService : IIdentityMessageService | ||
{ | ||
public Task SendAsync(IdentityMessage message) | ||
{ | ||
// Plug in your email service here to send an email. | ||
return Task.FromResult(0); | ||
} | ||
} | ||
|
||
public class SmsService : IIdentityMessageService | ||
{ | ||
public Task SendAsync(IdentityMessage message) | ||
{ | ||
// Plug in your SMS service here to send a text message. | ||
return Task.FromResult(0); | ||
} | ||
} | ||
|
||
// 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> | ||
{ | ||
public ApplicationUserManager(IUserStore<ApplicationUser> store) | ||
: base(store) | ||
{ | ||
} | ||
|
||
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) | ||
{ | ||
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>())); | ||
// Configure validation logic for usernames | ||
manager.UserValidator = new UserValidator<ApplicationUser>(manager) | ||
{ | ||
AllowOnlyAlphanumericUserNames = false, | ||
RequireUniqueEmail = true | ||
}; | ||
|
||
// Configure validation logic for passwords | ||
manager.PasswordValidator = new PasswordValidator | ||
{ | ||
RequiredLength = 6, | ||
RequireNonLetterOrDigit = true, | ||
RequireDigit = true, | ||
RequireLowercase = true, | ||
RequireUppercase = true, | ||
}; | ||
|
||
// Configure user lockout defaults | ||
manager.UserLockoutEnabledByDefault = true; | ||
manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5); | ||
manager.MaxFailedAccessAttemptsBeforeLockout = 5; | ||
|
||
// Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user | ||
// You can write your own provider and plug it in here. | ||
manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<ApplicationUser> | ||
{ | ||
MessageFormat = "Your security code is {0}" | ||
}); | ||
manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser> | ||
{ | ||
Subject = "Security Code", | ||
BodyFormat = "Your security code is {0}" | ||
}); | ||
manager.EmailService = new EmailService(); | ||
manager.SmsService = new SmsService(); | ||
var dataProtectionProvider = options.DataProtectionProvider; | ||
if (dataProtectionProvider != null) | ||
{ | ||
manager.UserTokenProvider = | ||
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity")); | ||
} | ||
return manager; | ||
} | ||
} | ||
|
||
// Configure the application sign-in manager which is used in this application. | ||
public class ApplicationSignInManager : SignInManager<ApplicationUser, string> | ||
{ | ||
public ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager) | ||
: base(userManager, authenticationManager) | ||
{ | ||
} | ||
|
||
public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser user) | ||
{ | ||
return user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager); | ||
} | ||
|
||
public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context) | ||
{ | ||
return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.Authentication); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Samples/net46/CSharp/AspNetSamples/MvcDemo/App_Start/RouteConfig.cs
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
using System.Web.Routing; | ||
|
||
namespace MvcDemo | ||
{ | ||
public class RouteConfig | ||
{ | ||
public static void RegisterRoutes(RouteCollection routes) | ||
{ | ||
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | ||
|
||
routes.MapRoute( | ||
name: "Default", | ||
url: "{controller}/{action}/{id}", | ||
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } | ||
); | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
Samples/net46/CSharp/AspNetSamples/MvcDemo/App_Start/Startup.Auth.cs
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using System; | ||
using Microsoft.AspNet.Identity; | ||
using Microsoft.AspNet.Identity.Owin; | ||
using Microsoft.Owin; | ||
using Microsoft.Owin.Security.Cookies; | ||
using Microsoft.Owin.Security.Google; | ||
using Owin; | ||
using MvcDemo.Models; | ||
|
||
namespace MvcDemo | ||
{ | ||
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 | ||
app.CreatePerOwinContext(ApplicationDbContext.Create); | ||
app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); | ||
app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.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 | ||
// Configure the sign in cookie | ||
app.UseCookieAuthentication(new CookieAuthenticationOptions | ||
{ | ||
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, | ||
LoginPath = new PathString("/Account/Login"), | ||
Provider = new CookieAuthenticationProvider | ||
{ | ||
// Enables the application to validate the security stamp when the user logs in. | ||
// This is a security feature which is used when you change a password or add an external login to your account. | ||
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>( | ||
validateInterval: TimeSpan.FromMinutes(30), | ||
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager)) | ||
} | ||
}); | ||
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); | ||
|
||
// Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. | ||
app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); | ||
|
||
// Enables the application to remember the second login verification factor such as phone or email. | ||
// Once you check this option, your second step of verification during the login process will be remembered on the device where you logged in from. | ||
// This is similar to the RememberMe option when you log in. | ||
app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie); | ||
|
||
// Uncomment the following lines to enable logging in with third party login providers | ||
//app.UseMicrosoftAccountAuthentication( | ||
// clientId: "", | ||
// clientSecret: ""); | ||
|
||
//app.UseTwitterAuthentication( | ||
// consumerKey: "", | ||
// consumerSecret: ""); | ||
|
||
//app.UseFacebookAuthentication( | ||
// appId: "", | ||
// appSecret: ""); | ||
|
||
//app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() | ||
//{ | ||
// ClientId = "", | ||
// ClientSecret = "" | ||
//}); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Samples/net46/CSharp/AspNetSamples/MvcDemo/ApplicationInsights.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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings"> | ||
<TelemetryModules> | ||
<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector"/> | ||
<Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector"> | ||
<!-- | ||
Use the following syntax here to collect additional performance counters: | ||
<Counters> | ||
<Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" /> | ||
... | ||
</Counters> | ||
PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName | ||
Counter names may only contain letters, round brackets, forward slashes, hyphens, underscores, spaces and dots. | ||
You may provide an optional ReportAs attribute which will be used as the metric name when reporting counter data. | ||
For the purposes of reporting, metric names will be sanitized by removing all invalid characters from the resulting metric name. | ||
NOTE: performance counters configuration will be lost upon NuGet upgrade. | ||
The following placeholders are supported as InstanceName: | ||
??APP_WIN32_PROC?? - instance name of the application process for Win32 counters. | ||
??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters. | ||
??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters. | ||
--> | ||
</Add> | ||
<Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights"/> | ||
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web"/> | ||
</TelemetryModules> | ||
<TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/> | ||
<!-- | ||
Learn more about Application Insights configuration with ApplicationInsights.config here: | ||
http://go.microsoft.com/fwlink/?LinkID=513840 | ||
Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file. | ||
--> | ||
<TelemetryInitializers> | ||
<Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/> | ||
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DomainNameRoleInstanceTelemetryInitializer, Microsoft.AI.WindowsServer"/> | ||
<Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer"/> | ||
<Add Type="Microsoft.ApplicationInsights.WindowsServer.DeviceTelemetryInitializer, Microsoft.AI.WindowsServer"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.SyntheticTelemetryInitializer, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.UserAgentTelemetryInitializer, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.OperationIdTelemetryInitializer, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web"/> | ||
<Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web"/> | ||
</TelemetryInitializers> | ||
<!-- | ||
Learn more about Application Insights configuration with ApplicationInsights.config here: | ||
http://go.microsoft.com/fwlink/?LinkID=513840 | ||
Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file. | ||
--></ApplicationInsights> |
24 changes: 24 additions & 0 deletions
24
Samples/net46/CSharp/AspNetSamples/MvcDemo/Content/Site.css
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
body { | ||
padding-top: 50px; | ||
padding-bottom: 20px; | ||
} | ||
|
||
/* Set padding to keep content from hitting the edges */ | ||
.body-content { | ||
padding-left: 15px; | ||
padding-right: 15px; | ||
} | ||
|
||
/* Override the default bootstrap behavior where horizontal description lists | ||
will truncate terms that are too long to fit in the left column | ||
*/ | ||
.dl-horizontal dt { | ||
white-space: normal; | ||
} | ||
|
||
/* Set width on the form input elements since they're 100% wide by default */ | ||
input, | ||
select, | ||
textarea { | ||
max-width: 280px; | ||
} |
Oops, something went wrong.