<?xml version="1.0" encoding="utf-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><language>en</language><title>Blog posts by SveinAandahl</title> <link>https://world.optimizely.com/blogs/SveinAandahl/</link><description></description><ttl>60</ttl><generator>Optimizely World</generator><item> <title>How to setup OpenIdConnect integration between Azure AD B2C and Episerver</title>            <link>http://sveinaandahl.blogspot.com/2017/07/how-to-setup-openidconnect-integration.html</link>            <description>Setting up OpenIdConnect integration between Azure AD B2C and EPiserver isn’t straight forward. Together with my college Hugo Moen, we will share with you how we solved this.&lt;br /&gt;&lt;br /&gt;This type of Identity Server can handle up to 10 million users. We found out it can be very interesting for small solutions too, since there are now cost with less than 50 thousand users and up to 50 thousand logins per month. You would need to require an azure subscription to use this service, but you probably have one if you have hosted an Episerver solution in Azure.  &lt;br /&gt;&lt;br /&gt;&lt;b&gt;What’s the different between Azure AD and Azure AD B2C?&lt;/b&gt;&lt;br /&gt;Azure AD is a directory service with the goal to server organizations and their needs for identity management in the cloud.&lt;br /&gt;&lt;br /&gt;Azure AD B2C is another service built on the same technology, but not on the same in functionality as Azure AD. Azure AD B2C target is to build a directory for consumer applications where users can register with e-mail ID or social providers like LinkedIn, Facebook, Google and so on. The goal for Azure AD B2C is to allow organizations to manage single directory of customer identities shared among all applications.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some more information can be found here:&amp;nbsp;&lt;a href=&quot;https://www.blogger.com/:%20http://predica.pl/blog/azure-ad-b2b-b2c-puzzled-out/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;http://predica.pl/blog/azure-ad-b2b-b2c-puzzled-out/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Setting up Azure AD B2C&lt;/b&gt;&lt;/div&gt;&lt;div&gt;In&lt;a href=&quot;https://portal.azure.com/&quot; target=&quot;_blank&quot;&gt; https://portal.azure.com&lt;/a&gt; you will setup Azure AD B2C. You can read more about how to do that here:&amp;nbsp;&lt;a href=&quot;https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started&quot; target=&quot;_blank&quot;&gt;https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;Adding Groups&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Today in Episerver we use groups to set access right to different pages, blocks and folders. We usually use WebAdmins or Administrators. In Azure AD B2C you can manage users and groups.&lt;br /&gt;But this Azure AD B2C groups isn&#39;t a part of the claims in the token you recive after you have loggedin, so we would have to fetch them through the graph api after you have been authenticated.&lt;br /&gt;&lt;br /&gt;When you create groups it&#39;s probably smart to call the first group &quot;WebAdmins&quot; to avoid challenges&amp;nbsp;with Episerver later on. The groups that&#39;s added to the users will be synchronized to episerver through the code later on.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://4.bp.blogspot.com/-oSsd29nhazA/WVn3ycGpHeI/AAAAAAAAAto/YqD13etCGicUUde0gPqk13tL2tBGYuTfgCLcBGAs/s1600/azuregroup.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;526&quot; data-original-width=&quot;698&quot; height=&quot;482&quot; src=&quot;https://4.bp.blogspot.com/-oSsd29nhazA/WVn3ycGpHeI/AAAAAAAAAto/YqD13etCGicUUde0gPqk13tL2tBGYuTfgCLcBGAs/s640/azuregroup.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://4.bp.blogspot.com/-XOS6OHWZeFA/WVn3z3jYk8I/AAAAAAAAAts/CT96ZbChNM49ndFXb4nF8AQ89cJKsLa3gCLcBGAs/s1600/azuremembers.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;453&quot; data-original-width=&quot;824&quot; height=&quot;352&quot; src=&quot;https://4.bp.blogspot.com/-XOS6OHWZeFA/WVn3z3jYk8I/AAAAAAAAAts/CT96ZbChNM49ndFXb4nF8AQ89cJKsLa3gCLcBGAs/s640/azuremembers.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The code in the example is applied to a &amp;nbsp;Episerver CMS 10 version with the Alloy templates.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;NB! Nuget Package&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Verify that this nuget package&lt;u&gt; isn’t &lt;/u&gt;installed in you in episerver solution:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;i&gt;EPiServer.CMS.UI.AspNetIdentity&lt;/i&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If it is, then remove it, since it’s doesn’t work well with other IAM integrations. You could end up getting null references in different views. You only need it if you are going to use Episerver’s own version for ASP.NET Identity 2.0. If you use it already on existing solution, I would recommed to wait to remove it until you got this new B2C solution up and running.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Install necessary Nuget Packages&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Now we need to install some nuget packages. Open the Tools &amp;gt; Nuget Package Manager &amp;gt; Package Manager Console and run this commands:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.Cookies&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Owin.Host.SystemWeb&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.OpenIdConnect&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To be able to use the Graph API you will also need these packages.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Azure.ActiveDirectory.GraphClient&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Code in Startup.cs&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Configuration;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Globalization;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Web;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Owin;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Extensions;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.Cookies;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.Notifications;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.OpenIdConnect;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; EPiServer.Security;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; EPiServer.ServiceLocation;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.IdentityModel.Clients.ActiveDirectory;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Azure.ActiveDirectory.GraphClient;&lt;br /&gt;&lt;br /&gt;[assembly: OwinStartup(&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(Alloydemo.Startup))]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; Alloydemo&lt;br /&gt;{&lt;br /&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; Startup&lt;br /&gt;    {&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; AAD_GRAPH_URI = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;https://graph.windows.net&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; clientId = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:ClientId&quot;&lt;/span&gt;];&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; appKey = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AppKey&quot;&lt;/span&gt;];&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; aadInstance = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AADInstance&quot;&lt;/span&gt;];&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; tenant = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:Tenant&quot;&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);&lt;br /&gt;        &lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; PostLogoutRedirectUri = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:PostLogoutRedirectUri&quot;&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; LogoutPath = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;/util/logout.aspx&quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; LoginUrl = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;/util/login.aspx&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Configuration(IAppBuilder app)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; authContext = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; AuthenticationContext(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Format(aadInstance, tenant));&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; clientCredential = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ClientCredential(clientId, appKey);&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; graphUri = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Uri(AAD_GRAPH_URI);&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; serviceRoot = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Uri(graphUri, tenant);&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.aadClient = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ActiveDirectoryClient(serviceRoot, &lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; () =&amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; AcquireGraphAPIAccessToken(AAD_GRAPH_URI, authContext, clientCredential));&lt;br /&gt;&lt;br /&gt;            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);&lt;br /&gt;            app.UseCookieAuthentication(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; CookieAuthenticationOptions());&lt;br /&gt;            app.UseOpenIdConnectAuthentication(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; OpenIdConnectAuthenticationOptions&lt;br /&gt;            {&lt;br /&gt;                ClientId = clientId,&lt;br /&gt;                Authority = authority,&lt;br /&gt;                PostLogoutRedirectUri = PostLogoutRedirectUri,&lt;br /&gt;                TokenValidationParameters = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; System.IdentityModel.Tokens.TokenValidationParameters&lt;br /&gt;                {&lt;br /&gt;                    ValidateIssuer = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;,&lt;br /&gt;                    RoleClaimType = ClaimTypes.Role&lt;br /&gt;                },&lt;br /&gt;                UseTokenLifetime = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;//To avoid that the session expires after 5 min &lt;/span&gt;&lt;br /&gt;                Notifications = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; OpenIdConnectAuthenticationNotifications&lt;br /&gt;                {&lt;br /&gt;                    AuthenticationFailed = context =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        context.HandleResponse();&lt;br /&gt;                        context.Response.Write(context.Exception.Message);&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    },&lt;br /&gt;                    AuthorizationCodeReceived = &lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; (context) =&amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; AuthorizationCodeReceived(context),&lt;br /&gt;                    RedirectToIdentityProvider = context =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style=&quot;color: green;&quot;&gt;// Here you can change the return uri based on multisite&lt;/span&gt;&lt;br /&gt;                        HandleMultiSitereturnUrl(context);&lt;br /&gt;&lt;br /&gt;                        &lt;span style=&quot;color: green;&quot;&gt;// To avoid a redirect loop to the federation server send 403 &lt;/span&gt;&lt;br /&gt;                        &lt;span style=&quot;color: green;&quot;&gt;// when user is authenticated but does not have access&lt;/span&gt;&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (context.OwinContext.Response.StatusCode == 401 &amp;amp;&amp;amp;&lt;br /&gt;                            context.OwinContext.Authentication.User.Identity.IsAuthenticated)&lt;br /&gt;                        {&lt;br /&gt;                            context.OwinContext.Response.StatusCode = 403;&lt;br /&gt;                            context.HandleResponse();&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    },&lt;br /&gt;                    SecurityTokenValidated = (ctx) =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; redirectUri = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Uri(ctx.AuthenticationTicket.Properties.RedirectUri, UriKind.RelativeOrAbsolute);&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (redirectUri.IsAbsoluteUri)&lt;br /&gt;                        {&lt;br /&gt;                            ctx.AuthenticationTicket.Properties.RedirectUri = redirectUri.PathAndQuery;&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;            app.UseStageMarker(PipelineStage.Authenticate);&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: green;&quot;&gt;//Remap login&lt;/span&gt;&lt;br /&gt;            app.Map(LoginUrl, map =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                map.Run(ctx =&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (ctx.Authentication.User == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt; ||&lt;br /&gt;                        !ctx.Authentication.User.Identity.IsAuthenticated)&lt;br /&gt;                    {&lt;br /&gt;                        ctx.Response.StatusCode = 401;&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        ctx.Response.Redirect(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;/&quot;&lt;/span&gt;);&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                });&lt;br /&gt;            });&lt;br /&gt;            app.Map(LogoutPath, map =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                map.Run(ctx =&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    ctx.Authentication.SignOut();&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                });&lt;br /&gt;            });&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Task AuthorizationCodeReceived(AuthorizationCodeReceivedNotification context)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.Run(&lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; () =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; oidClaim = context.AuthenticationTicket.Identity.Claims.FirstOrDefault(c =&amp;gt; c.Type == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://schemas.microsoft.com/identity/claims/objectidentifier&quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; identity = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ClaimsIdentity(context.AuthenticationTicket.Identity.AuthenticationType);&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (identity.IsAuthenticated)&lt;br /&gt;                {&lt;br /&gt;                    identity.AddClaims(context.AuthenticationTicket.Identity.Claims);&lt;br /&gt;&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(oidClaim?.Value))&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; pagedCollection = &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.aadClient.Users.GetByObjectId(oidClaim.Value).MemberOf.ExecuteAsync();&lt;br /&gt;&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; directoryObjects = pagedCollection.CurrentPage.ToList();&lt;br /&gt;                            &lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; directoryObject &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; directoryObjects)&lt;br /&gt;                            {&lt;br /&gt;                                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; group = directoryObject &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; Group;&lt;br /&gt;                                &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (group != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;                                {&lt;br /&gt;                                    identity.AddClaim(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Claim(ClaimTypes.Role, group.DisplayName, ClaimValueTypes.String));&lt;br /&gt;                                }&lt;br /&gt;                            }&lt;br /&gt;                            pagedCollection = pagedCollection.MorePagesAvailable ? &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; pagedCollection.GetNextPageAsync() : &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (pagedCollection != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;);&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    context.AuthenticationTicket = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; AuthenticationTicket(&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ClaimsIdentity(identity.Claims, context.AuthenticationTicket.Identity.AuthenticationType), context.AuthenticationTicket.Properties);&lt;br /&gt;&lt;br /&gt;                    &lt;span style=&quot;color: green;&quot;&gt;//Sync user and the roles to EPiServer in the background&lt;/span&gt;&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; ServiceLocator.Current.GetInstance&amp;lt;ISynchronizingUserService&amp;gt;().SynchronizeAsync(context.AuthenticationTicket.Identity);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            });&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; Task&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; AcquireGraphAPIAccessToken(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; graphAPIUrl, AuthenticationContext authContext, ClientCredential clientCredential)&lt;br /&gt;        {&lt;br /&gt;            AuthenticationResult result = &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; retryCount = 0;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; retry = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                retry = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style=&quot;color: green;&quot;&gt;// ADAL includes an in-memory cache, so this will only send a request if the cached token has expired&lt;/span&gt;&lt;br /&gt;                    result = &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; authContext.AcquireTokenAsync(graphAPIUrl, clientCredential);&lt;br /&gt;                }&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (AdalException ex)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (ex.ErrorCode == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;temporarily_unavailable&quot;&lt;/span&gt;)&lt;br /&gt;                    {&lt;br /&gt;                        retry = &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;                        retryCount++;&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; Task.Delay(3000);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            } &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (retry &amp;amp;&amp;amp; (retryCount &amp;lt; 3));&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (result != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; result.AccessToken;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; HandleMultiSitereturnUrl(&lt;br /&gt;            RedirectToIdentityProviderNotification&amp;lt;Microsoft.IdentityModel.Protocols.OpenIdConnectMessage,&lt;br /&gt;                OpenIdConnectAuthenticationOptions&amp;gt; context)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: green;&quot;&gt;// here you change the context.ProtocolMessage.RedirectUri to corresponding siteurl&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: green;&quot;&gt;// this is a sample of how to change redirecturi in the multi-tenant environment&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (context.ProtocolMessage.RedirectUri == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; currentUrl = EPiServer.Web.SiteDefinition.Current.SiteUrl;&lt;br /&gt;                context.ProtocolMessage.RedirectUri = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; UriBuilder(&lt;br /&gt;                    currentUrl.Scheme,&lt;br /&gt;                    currentUrl.Host,&lt;br /&gt;                    currentUrl.Port,&lt;br /&gt;                    HttpContext.Current.Request.Url.AbsolutePath).ToString();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; ActiveDirectoryClient aadClient { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;Web.config&lt;/b&gt;&lt;br /&gt;Add the following code snippets into the web.config.&lt;br /&gt;&lt;br /&gt;&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 10pt;&quot;&gt;  &amp;lt;appSettings&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:ClientId&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AppKey&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&amp;lt;- app key -&amp;gt;&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:Tenant&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&amp;lt;-YourTenant-&amp;gt;.onmicrosoft.com&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AADInstance&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;https://login.microsoftonline.com/{0}&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:RedirectUri&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://localhost:7676/&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:PostLogoutRedirectUri&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://localhost:7676/&quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;  &amp;lt;/appSettings&amp;gt;&lt;br /&gt;..&lt;br /&gt; &amp;lt;authentication mode=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;None&quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;..&lt;br /&gt;    &amp;lt;membership&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;clear /&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/membership&amp;gt;&lt;br /&gt;    &amp;lt;roleManager enabled=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;false&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;clear /&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/roleManager&amp;gt;&lt;br /&gt;..&lt;br /&gt;  &amp;lt;episerver.framework&amp;gt;&lt;br /&gt;    &amp;lt;securityEntity&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;add name=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;SynchronizingProvider&quot;&lt;/span&gt; type=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;EPiServer.Security.SynchronizingRolesSecurityEntityProvider, EPiServer&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/securityEntity&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Access Rights to the Graph Api&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB!&lt;/b&gt; You need to set the correct access right to the Graph Api or else you will end up with a error like this after you have logged in:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;Insufficient privileges to complete the operation&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;So to fix this you have to install the Windows Azure AD Module for Windows PowerShell and apply the correct role to the application.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Use a domain administrator account, when starting up Powershell.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Directory role =&amp;gt; Global administrator&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Referring to the Microsoft documentation:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Ensure that your server meets the following Windows Azure AD Module for Windows PowerShell requirements:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Windows 7, Windows 8, Windows Server 2008 R2, or Windows Server 2012.&lt;/li&gt;&lt;li&gt;Microsoft .NET Framework 3.51 feature.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Download and install the appropriate Microsoft Online Services Sign-In Assistant version for your operating system (see &lt;a href=&quot;https://www.microsoft.com/en-us/download/details.aspx?id=41950&quot; target=&quot;_blank&quot;&gt; Microsoft Online Services Sign-In Assistant for IT Professionals RTW)&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&amp;nbsp;Install the Windows Azure Active Directory Module for Windows PowerShell (see&amp;nbsp;&lt;a href=&quot;http://connect.microsoft.com/site1164/Downloads/DownloadDetails.aspx?DownloadID=59185&quot; target=&quot;_blank&quot;&gt;Install the Windows Azure AD Module&lt;/a&gt;&amp;nbsp;).&lt;/li&gt;&lt;li&gt;Connect to Windows Azure AD by running the PowerShell command:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp;import-module MSOnline&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Logg on Azure:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Connect-MsolService =&amp;gt; Login screen pop up&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;List out application with ID&#39;s to find the correct application ID&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Get-MsolServicePrincipal | ft DisplayName, AppPrincipalId -AutoSize&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Set correct value and ID:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;$clientIdApp = &#39;XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX&#39;&lt;/li&gt;&lt;li&gt;$webApp = Get-MsolServicePrincipal –AppPrincipalId $clientIdApp&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Add a read role (&quot;Directory Readers&quot;)&amp;nbsp;to the application:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Add-MsolRoleMember -RoleName &quot;Directory Readers&quot; -RoleMemberType ServicePrincipal -RoleMemberObjectId $webApp.ObjectId&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;div&gt;So, if you have done everything correct, you should now be able to login to the Episerver through Azure AD B2C. The nice part is that if you use an AD account that is connected to other services, like office 365, you will have a perfect SSO solution.&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2017/07/how-to-setup-openidconnect-integration.html</guid>            <pubDate>Mon, 03 Jul 2017 11:09:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to setup OpenIdConnect integration between Azure AD B2C and Episerver</title>            <link>http://sveinaandahl.blogspot.com/2017/07/how-to-setup-openidconnect-integration.html</link>            <description>Setting up OpenIdConnect integration between Azure AD B2C and EPiserver isn’t straight forward. Together with my colleague Hugo Moen, we will share with you how we solved this.&lt;br /&gt;&lt;br /&gt;This type of Identity Server can handle up to 10 million users. We found out it can be very interesting for small solutions too, since there are now cost with less than 50 thousand users and up to 50 thousand logins per month. You would need to require an azure subscription to use this service, but you probably have one if you have hosted an Episerver solution in Azure.  &lt;br /&gt;&lt;br /&gt;&lt;b&gt;What’s the different between Azure AD and Azure AD B2C?&lt;/b&gt;&lt;br /&gt;Azure AD is a directory service with the goal to server organizations and their needs for identity management in the cloud.&lt;br /&gt;&lt;br /&gt;Azure AD B2C is another service built on the same technology, but not on the same in functionality as Azure AD. Azure AD B2C target is to build a directory for consumer applications where users can register with e-mail ID or social providers like LinkedIn, Facebook, Google and so on. The goal for Azure AD B2C is to allow organizations to manage single directory of customer identities shared among all applications.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Some more information can be found here:&amp;nbsp;&lt;a href=&quot;https://www.blogger.com/:%20http://predica.pl/blog/azure-ad-b2b-b2c-puzzled-out/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;http://predica.pl/blog/azure-ad-b2b-b2c-puzzled-out/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Setting up Azure AD B2C&lt;/b&gt;&lt;/div&gt;&lt;div&gt;In&lt;a href=&quot;https://portal.azure.com/&quot; target=&quot;_blank&quot;&gt; https://portal.azure.com&lt;/a&gt; you will setup Azure AD B2C. You can read more about how to do that here:&amp;nbsp;&lt;a href=&quot;https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started&quot; target=&quot;_blank&quot;&gt;https://docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;Adding Groups&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Today in Episerver we use groups to set access right to different pages, blocks and folders. We usually use WebAdmins or Administrators. In Azure AD B2C you can manage users and groups.&lt;br /&gt;But this Azure AD B2C groups isn&#39;t a part of the claims in the token you recive after you have loggedin, so we would have to fetch them through the graph api after you have been authenticated.&lt;br /&gt;&lt;br /&gt;When you create groups it&#39;s probably smart to call the first group &quot;WebAdmins&quot; to avoid challenges&amp;nbsp;with Episerver later on. The groups that&#39;s added to the users will be synchronized to episerver through the code later on.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://4.bp.blogspot.com/-oSsd29nhazA/WVn3ycGpHeI/AAAAAAAAAto/YqD13etCGicUUde0gPqk13tL2tBGYuTfgCLcBGAs/s1600/azuregroup.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;526&quot; data-original-width=&quot;698&quot; height=&quot;482&quot; src=&quot;https://4.bp.blogspot.com/-oSsd29nhazA/WVn3ycGpHeI/AAAAAAAAAto/YqD13etCGicUUde0gPqk13tL2tBGYuTfgCLcBGAs/s640/azuregroup.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://4.bp.blogspot.com/-XOS6OHWZeFA/WVn3z3jYk8I/AAAAAAAAAts/CT96ZbChNM49ndFXb4nF8AQ89cJKsLa3gCLcBGAs/s1600/azuremembers.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; data-original-height=&quot;453&quot; data-original-width=&quot;824&quot; height=&quot;352&quot; src=&quot;https://4.bp.blogspot.com/-XOS6OHWZeFA/WVn3z3jYk8I/AAAAAAAAAts/CT96ZbChNM49ndFXb4nF8AQ89cJKsLa3gCLcBGAs/s640/azuremembers.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The code in the example is applied to a &amp;nbsp;Episerver CMS 10 version with the Alloy templates.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;NB! Nuget Package&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Verify that this nuget package&lt;u&gt; isn’t &lt;/u&gt;installed in you in episerver solution:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;i&gt;EPiServer.CMS.UI.AspNetIdentity&lt;/i&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If it is, then remove it, since it’s doesn’t work well with other IAM integrations. You could end up getting null references in different views. You only need it if you are going to use Episerver’s own version for ASP.NET Identity 2.0. If you use it already on existing solution, I would recommed to wait to remove it until you got this new B2C solution up and running.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Install necessary Nuget Packages&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Now we need to install some nuget packages. Open the Tools &amp;gt; Nuget Package Manager &amp;gt; Package Manager Console and run this commands:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.Cookies&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Owin.Host.SystemWeb&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.OpenIdConnect&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To be able to use the Graph API you will also need these packages.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.Azure.ActiveDirectory.GraphClient&lt;/div&gt;&lt;div&gt;PM&amp;gt; Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Code in Startup.cs&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Configuration;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Globalization;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; System.Web;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Owin;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Extensions;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.Cookies;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.Notifications;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.OpenIdConnect;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; EPiServer.Security;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; EPiServer.ServiceLocation;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.IdentityModel.Clients.ActiveDirectory;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;using&lt;/span&gt; Microsoft.Azure.ActiveDirectory.GraphClient;&lt;br /&gt;&lt;br /&gt;[assembly: OwinStartup(&lt;span style=&quot;color: blue;&quot;&gt;typeof&lt;/span&gt;(Alloydemo.Startup))]&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: blue;&quot;&gt;namespace&lt;/span&gt; Alloydemo&lt;br /&gt;{&lt;br /&gt;    &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;class&lt;/span&gt; Startup&lt;br /&gt;    {&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; AAD_GRAPH_URI = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;https://graph.windows.net&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; clientId = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:ClientId&quot;&lt;/span&gt;];&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; appKey = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AppKey&quot;&lt;/span&gt;];&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; aadInstance = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AADInstance&quot;&lt;/span&gt;];&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; tenant = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:Tenant&quot;&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenant);&lt;br /&gt;        &lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;static&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;readonly&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; PostLogoutRedirectUri = ConfigurationManager.AppSettings[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:PostLogoutRedirectUri&quot;&lt;/span&gt;];&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; LogoutPath = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;/util/logout.aspx&quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;const&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; LoginUrl = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;/util/login.aspx&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Configuration(IAppBuilder app)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; authContext = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; AuthenticationContext(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Format(aadInstance, tenant));&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; clientCredential = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ClientCredential(clientId, appKey);&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; graphUri = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Uri(AAD_GRAPH_URI);&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; serviceRoot = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Uri(graphUri, tenant);&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.aadClient = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ActiveDirectoryClient(serviceRoot, &lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; () =&amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; AcquireGraphAPIAccessToken(AAD_GRAPH_URI, authContext, clientCredential));&lt;br /&gt;&lt;br /&gt;            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);&lt;br /&gt;            app.UseCookieAuthentication(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; CookieAuthenticationOptions());&lt;br /&gt;            app.UseOpenIdConnectAuthentication(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; OpenIdConnectAuthenticationOptions&lt;br /&gt;            {&lt;br /&gt;                ClientId = clientId,&lt;br /&gt;                Authority = authority,&lt;br /&gt;                PostLogoutRedirectUri = PostLogoutRedirectUri,&lt;br /&gt;                TokenValidationParameters = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; System.IdentityModel.Tokens.TokenValidationParameters&lt;br /&gt;                {&lt;br /&gt;                    ValidateIssuer = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;,&lt;br /&gt;                    RoleClaimType = ClaimTypes.Role&lt;br /&gt;                },&lt;br /&gt;                UseTokenLifetime = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;, &lt;span style=&quot;color: green;&quot;&gt;//To avoid that the session expires after 5 min &lt;/span&gt;&lt;br /&gt;                Notifications = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; OpenIdConnectAuthenticationNotifications&lt;br /&gt;                {&lt;br /&gt;                    AuthenticationFailed = context =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        context.HandleResponse();&lt;br /&gt;                        context.Response.Write(context.Exception.Message);&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    },&lt;br /&gt;                    AuthorizationCodeReceived = &lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; (context) =&amp;gt; &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; AuthorizationCodeReceived(context),&lt;br /&gt;                    RedirectToIdentityProvider = context =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style=&quot;color: green;&quot;&gt;// Here you can change the return uri based on multisite&lt;/span&gt;&lt;br /&gt;                        HandleMultiSitereturnUrl(context);&lt;br /&gt;&lt;br /&gt;                        &lt;span style=&quot;color: green;&quot;&gt;// To avoid a redirect loop to the federation server send 403 &lt;/span&gt;&lt;br /&gt;                        &lt;span style=&quot;color: green;&quot;&gt;// when user is authenticated but does not have access&lt;/span&gt;&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (context.OwinContext.Response.StatusCode == 401 &amp;amp;&amp;amp;&lt;br /&gt;                            context.OwinContext.Authentication.User.Identity.IsAuthenticated)&lt;br /&gt;                        {&lt;br /&gt;                            context.OwinContext.Response.StatusCode = 403;&lt;br /&gt;                            context.HandleResponse();&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    },&lt;br /&gt;                    SecurityTokenValidated = (ctx) =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; redirectUri = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Uri(ctx.AuthenticationTicket.Properties.RedirectUri, UriKind.RelativeOrAbsolute);&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (redirectUri.IsAbsoluteUri)&lt;br /&gt;                        {&lt;br /&gt;                            ctx.AuthenticationTicket.Properties.RedirectUri = redirectUri.PathAndQuery;&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;            app.UseStageMarker(PipelineStage.Authenticate);&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: green;&quot;&gt;//Remap login&lt;/span&gt;&lt;br /&gt;            app.Map(LoginUrl, map =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                map.Run(ctx =&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (ctx.Authentication.User == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt; ||&lt;br /&gt;                        !ctx.Authentication.User.Identity.IsAuthenticated)&lt;br /&gt;                    {&lt;br /&gt;                        ctx.Response.StatusCode = 401;&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        ctx.Response.Redirect(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;/&quot;&lt;/span&gt;);&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                });&lt;br /&gt;            });&lt;br /&gt;            app.Map(LogoutPath, map =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                map.Run(ctx =&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    ctx.Authentication.SignOut();&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                });&lt;br /&gt;            });&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; Task AuthorizationCodeReceived(AuthorizationCodeReceivedNotification context)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; Task.Run(&lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; () =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; oidClaim = context.AuthenticationTicket.Identity.Claims.FirstOrDefault(c =&amp;gt; c.Type == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://schemas.microsoft.com/identity/claims/objectidentifier&quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; identity = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ClaimsIdentity(context.AuthenticationTicket.Identity.AuthenticationType);&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (identity.IsAuthenticated)&lt;br /&gt;                {&lt;br /&gt;                    identity.AddClaims(context.AuthenticationTicket.Identity.Claims);&lt;br /&gt;&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(oidClaim?.Value))&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; pagedCollection = &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;this&lt;/span&gt;.aadClient.Users.GetByObjectId(oidClaim.Value).MemberOf.ExecuteAsync();&lt;br /&gt;&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; directoryObjects = pagedCollection.CurrentPage.ToList();&lt;br /&gt;                            &lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (&lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; directoryObject &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; directoryObjects)&lt;br /&gt;                            {&lt;br /&gt;                                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; group = directoryObject &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; Group;&lt;br /&gt;                                &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (group != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;                                {&lt;br /&gt;                                    identity.AddClaim(&lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Claim(ClaimTypes.Role, group.DisplayName, ClaimValueTypes.String));&lt;br /&gt;                                }&lt;br /&gt;                            }&lt;br /&gt;                            pagedCollection = pagedCollection.MorePagesAvailable ? &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; pagedCollection.GetNextPageAsync() : &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (pagedCollection != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;);&lt;br /&gt;                    }&lt;br /&gt;&lt;br /&gt;                    context.AuthenticationTicket = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; AuthenticationTicket(&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ClaimsIdentity(identity.Claims, context.AuthenticationTicket.Identity.AuthenticationType), context.AuthenticationTicket.Properties);&lt;br /&gt;&lt;br /&gt;                    &lt;span style=&quot;color: green;&quot;&gt;//Sync user and the roles to EPiServer in the background&lt;/span&gt;&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; ServiceLocator.Current.GetInstance&amp;lt;ISynchronizingUserService&amp;gt;().SynchronizeAsync(context.AuthenticationTicket.Identity);&lt;br /&gt;                }&lt;br /&gt;&lt;br /&gt;            });&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;async&lt;/span&gt; Task&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; AcquireGraphAPIAccessToken(&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; graphAPIUrl, AuthenticationContext authContext, ClientCredential clientCredential)&lt;br /&gt;        {&lt;br /&gt;            AuthenticationResult result = &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; retryCount = 0;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; retry = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;do&lt;/span&gt;&lt;br /&gt;            {&lt;br /&gt;                retry = &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;;&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;try&lt;/span&gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style=&quot;color: green;&quot;&gt;// ADAL includes an in-memory cache, so this will only send a request if the cached token has expired&lt;/span&gt;&lt;br /&gt;                    result = &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; authContext.AcquireTokenAsync(graphAPIUrl, clientCredential);&lt;br /&gt;                }&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;catch&lt;/span&gt; (AdalException ex)&lt;br /&gt;                {&lt;br /&gt;                    &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (ex.ErrorCode == &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;temporarily_unavailable&quot;&lt;/span&gt;)&lt;br /&gt;                    {&lt;br /&gt;                        retry = &lt;span style=&quot;color: blue;&quot;&gt;true&lt;/span&gt;;&lt;br /&gt;                        retryCount++;&lt;br /&gt;                        &lt;span style=&quot;color: blue;&quot;&gt;await&lt;/span&gt; Task.Delay(3000);&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            } &lt;span style=&quot;color: blue;&quot;&gt;while&lt;/span&gt; (retry &amp;amp;&amp;amp; (retryCount &amp;lt; 3));&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (result != &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; result.AccessToken;&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;private&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; HandleMultiSitereturnUrl(&lt;br /&gt;            RedirectToIdentityProviderNotification&amp;lt;Microsoft.IdentityModel.Protocols.OpenIdConnectMessage,&lt;br /&gt;                OpenIdConnectAuthenticationOptions&amp;gt; context)&lt;br /&gt;        {&lt;br /&gt;            &lt;span style=&quot;color: green;&quot;&gt;// here you change the context.ProtocolMessage.RedirectUri to corresponding siteurl&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: green;&quot;&gt;// this is a sample of how to change redirecturi in the multi-tenant environment&lt;/span&gt;&lt;br /&gt;            &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (context.ProtocolMessage.RedirectUri == &lt;span style=&quot;color: blue;&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;            {&lt;br /&gt;                &lt;span style=&quot;color: blue;&quot;&gt;var&lt;/span&gt; currentUrl = EPiServer.Web.SiteDefinition.Current.SiteUrl;&lt;br /&gt;                context.ProtocolMessage.RedirectUri = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; UriBuilder(&lt;br /&gt;                    currentUrl.Scheme,&lt;br /&gt;                    currentUrl.Host,&lt;br /&gt;                    currentUrl.Port,&lt;br /&gt;                    HttpContext.Current.Request.Url.AbsolutePath).ToString();&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span style=&quot;color: blue;&quot;&gt;public&lt;/span&gt; ActiveDirectoryClient aadClient { &lt;span style=&quot;color: blue;&quot;&gt;get&lt;/span&gt;; &lt;span style=&quot;color: blue;&quot;&gt;set&lt;/span&gt;; }&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;Web.config&lt;/b&gt;&lt;br /&gt;Add the following code snippets into the web.config.&lt;br /&gt;&lt;br /&gt;&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: &amp;quot;consolas&amp;quot; , &amp;quot;courier new&amp;quot; , &amp;quot;courier&amp;quot; , monospace; font-size: 10pt;&quot;&gt;  &amp;lt;appSettings&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:ClientId&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AppKey&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&amp;lt;- app key -&amp;gt;&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:Tenant&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&amp;lt;-YourTenant-&amp;gt;.onmicrosoft.com&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:AADInstance&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;https://login.microsoftonline.com/{0}&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:RedirectUri&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://localhost:7676/&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;add key=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ida:PostLogoutRedirectUri&quot;&lt;/span&gt; value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;http://localhost:7676/&quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;  &amp;lt;/appSettings&amp;gt;&lt;br /&gt;..&lt;br /&gt; &amp;lt;authentication mode=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;None&quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;..&lt;br /&gt;    &amp;lt;membership&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;clear /&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/membership&amp;gt;&lt;br /&gt;    &amp;lt;roleManager enabled=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;false&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;clear /&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/roleManager&amp;gt;&lt;br /&gt;..&lt;br /&gt;  &amp;lt;episerver.framework&amp;gt;&lt;br /&gt;    &amp;lt;securityEntity&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;add name=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;SynchronizingProvider&quot;&lt;/span&gt; type=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;EPiServer.Security.SynchronizingRolesSecurityEntityProvider, EPiServer&quot;&lt;/span&gt; /&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/securityEntity&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Access Rights to the Graph Api&amp;nbsp;&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB!&lt;/b&gt; You need to set the correct access right to the Graph Api or else you will end up with a error like this after you have logged in:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;Insufficient privileges to complete the operation&lt;/i&gt;&lt;/b&gt;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;So to fix this you have to install the Windows Azure AD Module for Windows PowerShell and apply the correct role to the application.&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Use a domain administrator account, when starting up Powershell.&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Directory role =&amp;gt; Global administrator&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Referring to the Microsoft documentation:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Ensure that your server meets the following Windows Azure AD Module for Windows PowerShell requirements:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Windows 7, Windows 8, Windows Server 2008 R2, or Windows Server 2012.&lt;/li&gt;&lt;li&gt;Microsoft .NET Framework 3.51 feature.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Download and install the appropriate Microsoft Online Services Sign-In Assistant version for your operating system (see &lt;a href=&quot;https://www.microsoft.com/en-us/download/details.aspx?id=41950&quot; target=&quot;_blank&quot;&gt; Microsoft Online Services Sign-In Assistant for IT Professionals RTW)&lt;/a&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;&amp;nbsp;Install the Windows Azure Active Directory Module for Windows PowerShell (see&amp;nbsp;&lt;a href=&quot;http://connect.microsoft.com/site1164/Downloads/DownloadDetails.aspx?DownloadID=59185&quot; target=&quot;_blank&quot;&gt;Install the Windows Azure AD Module&lt;/a&gt;&amp;nbsp;).&lt;/li&gt;&lt;li&gt;Connect to Windows Azure AD by running the PowerShell command:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp;import-module MSOnline&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Logg on Azure:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Connect-MsolService =&amp;gt; Login screen pop up&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;List out application with ID&#39;s to find the correct application ID&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Get-MsolServicePrincipal | ft DisplayName, AppPrincipalId -AutoSize&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Set correct value and ID:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;$clientIdApp = &#39;XXXXXX-XXXX-XXXX-XXXX-XXXXXXXX&#39;&lt;/li&gt;&lt;li&gt;$webApp = Get-MsolServicePrincipal –AppPrincipalId $clientIdApp&lt;/li&gt;&lt;/ul&gt;&lt;li&gt;Add a read role (&quot;Directory Readers&quot;)&amp;nbsp;to the application:&lt;/li&gt;&lt;ul&gt;&lt;li&gt;Add-MsolRoleMember -RoleName &quot;Directory Readers&quot; -RoleMemberType ServicePrincipal -RoleMemberObjectId $webApp.ObjectId&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;/ol&gt;&lt;div&gt;So, if you have done everything correct, you should now be able to login to the Episerver through Azure AD B2C. The nice part is that if you use an AD account that is connected to other services, like office 365, you will have a perfect SSO solution.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;EDIT&lt;/b&gt;:&lt;br /&gt;&lt;br /&gt;You can also use this same approach for for Azure AD, but need to add following steps.&lt;br /&gt;&lt;br /&gt;Ref: &lt;a href=&quot;https://joonasw.net/view/the-grant-requires-admin-permission&quot;&gt;https://joonasw.net/view/the-grant-requires-admin-permission&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the login url add &quot;&amp;amp;promt=admin_consent&quot;, example:&lt;br /&gt;&lt;br /&gt;https://login.microsoftonline.com/ef8a53ea-1a1c-4189-b792-c832dcaea568/oauth2/authorize?client_id=c4386fb3-bc5b-494e-917f-fd64e7789f2a&amp;amp;response_mode=form_post&amp;amp;response_type=code+id_token&amp;amp;scope=openid+profile&amp;amp;state=OpenIdConnect.AuthenticationProperties%3dXJcVcEgbVsAldbQjX2Dp8dFStu_L2nT1CGUZu9QgwqocO3B_rfrAUuBd99k5AAblq6GVfyzMblfR2aAqlLCChKyQsREoyDKnnamAJzGETcaiUDa-ETcyA97AD5PM9RdpvXyoulkygC0jcHmeFaj2cbUaO0u0w-oyP2KyEJvDkIw9fNpg6znTuwjoEoi5sfk8r-Ja26SdDJ0Mgw&amp;amp;nonce=636516222037192017.YWINzEtMTkyNi00NmI1LWFiNmEtMTY5YjIwM2Y2ZjY3ZDY3ZjI5MmEtYWNiZS00ZDBkLWFmZTMWVhZTY2YzRmMTA2&amp;amp;redirect_uri=https%3a%2f%2fyourweb.episerver.com%3a443%2futil%2flogin.aspx&lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;amp;prompt=admin_consent&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Steps:&lt;br /&gt;1.&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Click on the login url which include the promt explained above.&lt;br /&gt;2.&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Login as Admin.&lt;br /&gt;3.&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Accept the consent.&lt;br /&gt;4.&lt;span style=&quot;white-space: pre;&quot;&gt; &lt;/span&gt;Then all the AD users should manage to login without getting a grant required error.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2017/07/how-to-setup-openidconnect-integration.html</guid>            <pubDate>Mon, 03 Jul 2017 09:09:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to setup OAuth2.0 integration between IdentityServer3 and Episerver</title>            <link>http://sveinaandahl.blogspot.com/2016/04/how-to-setup-oauth20-integration.html</link>            <description>There exists a couple blog post on how to integrate Episerver with WS-Federation protocol, which also is support in IdentityServer3. But this blog post will introduce to you, how to setup OAuth2.0 integration between Episerver and IdentityServer3. IdentityServer3 is a popular open source security token service framework written in .NET, that implements the OpenID Connect and OAuth2 protocols. In this example we use the “Hybrid”-flow, which also contain the refresh token that’s used to obtain and renewed the identity token. Which is a really nice feature in modern SSO strategy.&lt;br /&gt;&lt;br /&gt;For you who want to read an introduction to this, can click here:&amp;nbsp;&lt;a href=&quot;http://sveinaandahl.blogspot.no/2016/04/how-to-do-identity-and-access.html&quot; target=&quot;_blank&quot;&gt;http://sveinaandahl.blogspot.no/2016/04/how-to-do-identity-and-access.html&lt;/a&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://2.bp.blogspot.com/-JpEQUd3Hvzg/VxTbGtfVHiI/AAAAAAAAAqs/g4u-DjI3yoAPG875jNml_fCYgy4XEAMpwCLcB/s1600/Id-Login.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;562&quot; src=&quot;https://2.bp.blogspot.com/-JpEQUd3Hvzg/VxTbGtfVHiI/AAAAAAAAAqs/g4u-DjI3yoAPG875jNml_fCYgy4XEAMpwCLcB/s640/Id-Login.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;Install necessary Nuget Packages&lt;/b&gt;&lt;br /&gt;First of all you need to install som nuget packages. Open the Tools &amp;gt; Nuget Package Manager &amp;gt; Package Manager Console and run this commands:&lt;br /&gt;&lt;br /&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.Cookies&lt;br /&gt;PM&amp;gt; Install-Package Microsoft.Owin.Host.SystemWeb&lt;br /&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.OpenIdConnect&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NOTE&lt;/b&gt;&lt;br /&gt;&lt;div&gt;Since the implementaion of the OpenID Connect and OAuth2 protocols usually use JSON web token(JWT), the token format look something like this:&lt;br /&gt;&lt;i&gt;//claims&lt;/i&gt;&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&quot;sub&quot;: &quot;svein@knowit.no&quot;,&lt;br /&gt;&amp;nbsp;&quot;name&quot;: &quot;Svein Aandahl&quot;,&lt;br /&gt;&amp;nbsp;&quot;role&quot;: &quot;Administator&quot;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;While the URI in a assertion (claims) in a Saml1.1 token looks like this&lt;br /&gt;&lt;i&gt;Role and Name claim&lt;/i&gt;&lt;br /&gt;http://schemas.microsoft.com/ws/2008/06/identity/claims/role&lt;br /&gt;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name&lt;br /&gt;&lt;br /&gt;Why is this importen to be aware of? The Episerver implementation only support the Saml 1.1 token standard. So when you use the OAuth 2.0 you would need to adjust some of the code to make this work in Episerver.  &lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;Code in Startup.cs&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Create a startup.cs file on root and add following code.&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Security;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.ServiceLocation;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.Cookies;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Owin;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.IdentityModel.Tokens;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Helpers;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; IdentityModel.Client;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.IdentityModel.Protocols;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.OpenIdConnect;&lt;br /&gt;&lt;br /&gt;[assembly: OwinStartup(&lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(EPiServer.Templates.Alloy.Startup))]&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; EPiServer.Templates.Alloy&lt;br /&gt;{&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Startup&lt;br /&gt;    {&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; LogoutUrl = &lt;span class=&quot;str&quot;&gt;&quot;/util/logout.aspx&quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; LoginUrl = &lt;span class=&quot;str&quot;&gt;&quot;/login&quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; clientId = &lt;span class=&quot;str&quot;&gt;&quot;Client-Name&quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; IdSrvUrl = &lt;span class=&quot;str&quot;&gt;&quot;https://idsrv.local&quot;&lt;/span&gt;;&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ClientUrl = &lt;span class=&quot;str&quot;&gt;&quot;http://website.local/&quot;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Configuration(IAppBuilder app)&lt;br /&gt;        {&lt;br /&gt;            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);&lt;br /&gt;&lt;br /&gt;            AntiForgeryConfig.UniqueClaimTypeIdentifier = &lt;span class=&quot;str&quot;&gt;&quot;sub&quot;&lt;/span&gt;;&lt;br /&gt;            JwtSecurityTokenHandler.InboundClaimTypeMap = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;            JwtSecurityTokenHandler.OutboundClaimTypeMap = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;&amp;gt;();&lt;br /&gt;&lt;br /&gt;            &lt;span class=&quot;rem&quot;&gt;// Sets the authentication type for the owin middleware&lt;/span&gt;&lt;br /&gt;            app.UseCookieAuthentication(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CookieAuthenticationOptions&lt;br /&gt;            {&lt;br /&gt;                AuthenticationType = &lt;span class=&quot;str&quot;&gt;&quot;Cookies&quot;&lt;/span&gt;&lt;br /&gt;            });&lt;br /&gt;&lt;br /&gt;            &lt;span class=&quot;rem&quot;&gt;// Uses OpenIdConnect middleware for authentication&lt;/span&gt;&lt;br /&gt;            app.UseOpenIdConnectAuthentication(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; OpenIdConnectAuthenticationOptions&lt;br /&gt;            {&lt;br /&gt;                ClientId = clientId,&lt;br /&gt;&lt;br /&gt;                Authority = IdSrvUrl + &lt;span class=&quot;str&quot;&gt;&quot;/core/&quot;&lt;/span&gt;, &lt;br /&gt;                RedirectUri = ClientUrl, &lt;br /&gt;                PostLogoutRedirectUri = ClientUrl, &lt;br /&gt;                ResponseType = &lt;span class=&quot;str&quot;&gt;&quot;code id_token token&quot;&lt;/span&gt;,&lt;br /&gt;                Scope = &lt;span class=&quot;str&quot;&gt;&quot;openid email profile offline_access roles&quot;&lt;/span&gt;,&lt;br /&gt;                UseTokenLifetime = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;, &lt;span class=&quot;rem&quot;&gt;//To avoid that the session expires after 5 min &lt;/span&gt;&lt;br /&gt;                SignInAsAuthenticationType = &lt;span class=&quot;str&quot;&gt;&quot;Cookies&quot;&lt;/span&gt;,&lt;br /&gt;&lt;br /&gt;                Notifications = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; OpenIdConnectAuthenticationNotifications&lt;br /&gt;                {&lt;br /&gt;                    AuthorizationCodeReceived = async n =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class=&quot;rem&quot;&gt;// use the code to get the access and refresh token&lt;/span&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; tokenClient = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; TokenClient(&lt;br /&gt;                            IdSrvUrl + &lt;span class=&quot;str&quot;&gt;&quot;/core/connect/token&quot;&lt;/span&gt;,&lt;br /&gt;                            clientId, &lt;br /&gt;                            &lt;span class=&quot;str&quot;&gt;&quot;secret&quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; tokenResponse = await tokenClient.RequestAuthorizationCodeAsync(n.Code, n.RedirectUri);&lt;br /&gt;&lt;br /&gt;                        &lt;span class=&quot;rem&quot;&gt;// use the access token to retrieve claims from userinfo&lt;/span&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; userInfoClient = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; UserInfoClient(&lt;br /&gt;                            &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Uri(IdSrvUrl + &lt;span class=&quot;str&quot;&gt;&quot;/core/connect/userinfo&quot;&lt;/span&gt;),&lt;br /&gt;                            tokenResponse.AccessToken);&lt;br /&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; userInfoResponse = await userInfoClient.GetAsync();&lt;br /&gt;&lt;br /&gt;                        &lt;span class=&quot;rem&quot;&gt;// create new identity&lt;/span&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; id = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ClaimsIdentity(n.AuthenticationTicket.Identity.AuthenticationType);&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (id.IsAuthenticated)&lt;br /&gt;                        { &lt;br /&gt;                            id.AddClaims(userInfoResponse.GetClaimsIdentity().Claims);&lt;br /&gt;                        &lt;br /&gt;                            &lt;span class=&quot;rem&quot;&gt;// Add name claim as http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name&lt;/span&gt;&lt;br /&gt;                            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; name = id.Claims.Where(x =&amp;gt; x.Type == &lt;span class=&quot;str&quot;&gt;&quot;name&quot;&lt;/span&gt;).Select(x =&amp;gt; x.Value).FirstOrDefault() ?? &lt;br /&gt;                                       id.Claims.Where(x =&amp;gt; x.Type == &lt;span class=&quot;str&quot;&gt;&quot;preferred_username&quot;&lt;/span&gt;).Select(x =&amp;gt; x.Value).FirstOrDefault();&lt;br /&gt;                            id.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Claim(ClaimTypes.Name, name));&lt;br /&gt;&lt;br /&gt;                            &lt;span class=&quot;rem&quot;&gt;// Add all role claims for the user as http://schemas.microsoft.com/ws/2008/06/identity/claims/role&lt;/span&gt;&lt;br /&gt;                            IEnumerable&amp;lt;Claim&amp;gt; roles = id.Claims.Where(x =&amp;gt; x.Type == &lt;span class=&quot;str&quot;&gt;&quot;role&quot;&lt;/span&gt;);&lt;br /&gt;                            &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; role &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; roles)&lt;br /&gt;                            {&lt;br /&gt;                                id.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Claim(ClaimTypes.Role, role.Value));&lt;br /&gt;                            }&lt;br /&gt;&lt;br /&gt;                            id.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Claim(&lt;span class=&quot;str&quot;&gt;&quot;access_token&quot;&lt;/span&gt;, tokenResponse.AccessToken));&lt;br /&gt;                            id.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Claim(&lt;span class=&quot;str&quot;&gt;&quot;expires_at&quot;&lt;/span&gt;, DateTime.Now.AddSeconds(tokenResponse.ExpiresIn).ToLocalTime().ToString()));&lt;br /&gt;                            id.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Claim(&lt;span class=&quot;str&quot;&gt;&quot;refresh_token&quot;&lt;/span&gt;, tokenResponse.RefreshToken));&lt;br /&gt;                            id.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Claim(&lt;span class=&quot;str&quot;&gt;&quot;id_token&quot;&lt;/span&gt;, n.ProtocolMessage.IdToken));&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                        n.AuthenticationTicket = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AuthenticationTicket(&lt;br /&gt;                            &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ClaimsIdentity(id.Claims, n.AuthenticationTicket.Identity.AuthenticationType),&lt;br /&gt;                            n.AuthenticationTicket.Properties);&lt;br /&gt;&lt;br /&gt;                    },&lt;br /&gt;&lt;br /&gt;                    RedirectToIdentityProvider = n =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class=&quot;rem&quot;&gt;// if signing out, add the id_token_hint&lt;/span&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.LogoutRequest)&lt;br /&gt;                        {&lt;br /&gt;                            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; idTokenHint = n.OwinContext.Authentication.User.FindFirst(&lt;span class=&quot;str&quot;&gt;&quot;id_token&quot;&lt;/span&gt;);&lt;br /&gt;                            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (idTokenHint != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;br /&gt;                            {&lt;br /&gt;                                n.ProtocolMessage.IdTokenHint = idTokenHint.Value;&lt;br /&gt;                            }&lt;br /&gt;                        }&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    },&lt;br /&gt;&lt;br /&gt;                    SecurityTokenValidated = (ctx) =&amp;gt;&lt;br /&gt;                    {&lt;br /&gt;                        &lt;span class=&quot;rem&quot;&gt;//Ignore scheme/host name in redirect Uri to make sure a redirect to HTTPS does not redirect back to HTTP&lt;/span&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; redirectUri = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; Uri(ctx.AuthenticationTicket.Properties.RedirectUri, UriKind.RelativeOrAbsolute);&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (redirectUri.IsAbsoluteUri)&lt;br /&gt;                        {&lt;br /&gt;                            ctx.AuthenticationTicket.Properties.RedirectUri = redirectUri.PathAndQuery;&lt;br /&gt;                        }&lt;br /&gt;&lt;br /&gt;                        &lt;span class=&quot;rem&quot;&gt;//Sync user and the roles to EPiServer in the background&lt;/span&gt;&lt;br /&gt;                        ServiceLocator.Current.GetInstance&amp;lt;OAuth2SynchronizingUserService&amp;gt;().SynchronizeAsync(ctx.AuthenticationTicket.Identity);&lt;br /&gt;&lt;br /&gt;                        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                    },&lt;br /&gt;                }&lt;br /&gt;            });&lt;br /&gt;            &lt;span class=&quot;rem&quot;&gt;//Remap login&lt;/span&gt;&lt;br /&gt;            app.Map(LoginUrl, map =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                map.Run(ctx =&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (ctx.Authentication.User == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt; ||&lt;br /&gt;                        !ctx.Authentication.User.Identity.IsAuthenticated)&lt;br /&gt;                    {&lt;br /&gt;                        ctx.Response.StatusCode = 401;&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;br /&gt;                    {&lt;br /&gt;                        ctx.Response.Redirect(&lt;span class=&quot;str&quot;&gt;&quot;/&quot;&lt;/span&gt;);&lt;br /&gt;                    }&lt;br /&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                });&lt;br /&gt;            });&lt;br /&gt;            &lt;span class=&quot;rem&quot;&gt;//Remap logout &lt;/span&gt;&lt;br /&gt;            app.Map(LogoutUrl, map =&amp;gt;&lt;br /&gt;            {&lt;br /&gt;                map.Run(ctx =&amp;gt;&lt;br /&gt;                {&lt;br /&gt;                    ctx.Authentication.SignOut();&lt;br /&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;br /&gt;                });&lt;br /&gt;            });&lt;br /&gt;&lt;br /&gt;            &lt;span class=&quot;rem&quot;&gt;//Tell antiforgery to use the name claim&lt;/span&gt;&lt;br /&gt;            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To be able to sync roles up from Identity Server when the user login, we need to replace the &quot;http://schemas.microsoft.com/ws/2008/06/identity/claims/role&quot; with &quot;role&quot;. &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Async;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Framework;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Security;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.ServiceLocation;&lt;br /&gt;&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Business.ServiceLocation&lt;br /&gt;{&lt;br /&gt;    [ServiceConfiguration(&lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(SynchronizingUserService))]&lt;br /&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; OAuth2SynchronizingUserService : SynchronizingUserService&lt;br /&gt;    {&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; Task SynchronizeAsync(ClaimsIdentity identity)&lt;br /&gt;        {&lt;br /&gt;            Validator.ThrowIfNull(&lt;span class=&quot;str&quot;&gt;&quot;identity&quot;&lt;/span&gt;, identity);&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!identity.IsAuthenticated)&lt;br /&gt;                &lt;span class=&quot;kwrd&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ArgumentException(&lt;span class=&quot;str&quot;&gt;&quot;The identity is not authenticated&quot;&lt;/span&gt;, nameof(identity));&lt;br /&gt;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; name = identity.Name ?? identity.Claims.Single(c =&amp;gt; c.Type == &lt;span class=&quot;str&quot;&gt;&quot;aud&quot;&lt;/span&gt;).Value;&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; roles = GetRolesFromClaims(identity);&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; ServiceLocator.Current.GetInstance&amp;lt;TaskExecutor&amp;gt;().Start(() =&amp;gt; SynchronizeUserAndRoles(name, roles));&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; List&amp;lt;&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;&amp;gt; GetRolesFromClaims(ClaimsIdentity identity)&lt;br /&gt;        {&lt;br /&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; identity.Claims.Where(c =&amp;gt; c.Type == &lt;span class=&quot;str&quot;&gt;&quot;role&quot;&lt;/span&gt;).Where(c =&amp;gt; !&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;.IsNullOrEmpty(c.Value)).Select(c =&amp;gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;c.Value).Distinct(StringComparer.OrdinalIgnoreCase).ToList();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;Web.config&lt;/b&gt;&lt;/div&gt;&lt;div&gt;You need to do some modification in web.config and remove membership provider .&lt;/div&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;authentication mode=&lt;span class=&quot;str&quot;&gt;&quot;None&quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;membership&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;clear/&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/membership&amp;gt;&lt;br /&gt;    &amp;lt;roleManager enabled=&lt;span class=&quot;str&quot;&gt;&quot;false&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;clear/&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/roleManager&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;episerver.framework&amp;gt;&lt;br /&gt;    &amp;lt;securityEntity&amp;gt;&lt;br /&gt;      &amp;lt;providers&amp;gt;&lt;br /&gt;        &amp;lt;add name=&lt;span class=&quot;str&quot;&gt;&quot;SynchronizingProvider&quot;&lt;/span&gt; type =&lt;span class=&quot;str&quot;&gt;&quot;EPiServer.Security.SynchronizingRolesSecurityEntityProvider, EPiServer&quot;&lt;/span&gt;/&amp;gt;&lt;br /&gt;      &amp;lt;/providers&amp;gt;&lt;br /&gt;    &amp;lt;/securityEntity&amp;gt;&lt;br /&gt;    &amp;lt;virtualRoles addClaims=&lt;span class=&quot;str&quot;&gt;&quot;true&quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;       &lt;span class=&quot;rem&quot;&gt;//existing virtual roles&lt;/span&gt;&lt;br /&gt;    &amp;lt;/virtualRoles&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;Administration of users&lt;/b&gt;&lt;br /&gt;&lt;span lang=&quot;EN-US&quot;&gt;After you have got everything up and running with both episerver and IdentityServer then you need to go into the admin to create a user and add roles.&amp;nbsp;&lt;/span&gt;These roles will be populated in Episerver, so you can add them as groups in the Episerver tree.&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-78XbloLDZCw/VxTboLmFqfI/AAAAAAAAAqw/DiL4Fx2tnyU5LpiD8rqO_A2Dgr2EubuhwCLcB/s1600/IDAdmin1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;364&quot; src=&quot;https://1.bp.blogspot.com/-78XbloLDZCw/VxTboLmFqfI/AAAAAAAAAqw/DiL4Fx2tnyU5LpiD8rqO_A2Dgr2EubuhwCLcB/s640/IDAdmin1.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://4.bp.blogspot.com/-TTEUk8ziuQs/VxTboNH3vlI/AAAAAAAAAq0/itBmnqTz7yYpWkEV1ceCPlxKgoriWvV4QCLcB/s1600/IdAdmin2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;a href=&quot;https://4.bp.blogspot.com/-TTEUk8ziuQs/VxTboNH3vlI/AAAAAAAAAq0/itBmnqTz7yYpWkEV1ceCPlxKgoriWvV4QCLcB/s1600/IdAdmin2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;356&quot; src=&quot;https://4.bp.blogspot.com/-TTEUk8ziuQs/VxTboNH3vlI/AAAAAAAAAq0/itBmnqTz7yYpWkEV1ceCPlxKgoriWvV4QCLcB/s640/IdAdmin2.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;To be able to login to Episerver editor you need to add the name and role claim as minimum.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy coding!&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2016/04/how-to-setup-oauth20-integration.html</guid>            <pubDate>Mon, 25 Apr 2016 21:25:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to do Identity and Access Management with Episerver</title>            <link>http://sveinaandahl.blogspot.com/2016/04/how-to-do-identity-and-access.html</link>            <description>After working with Identity and Access Management (IAM) in a couple of large Episerver projects, I want to share some of the knowledge gained from this work. After Episerver upgraded their CMS platform to use OWIN you can pretty much replace the old membership provider with whatever IAM system you want. In this blog post I will introduce how to use OpenID Connect and OAuth2.0 through Identity Server 3 together with Episerver.&lt;br /&gt;&lt;br /&gt;The big advantage of claims based identity is that the burden of authenticating users is moved from the application to an identity server or identity provider. It’s important to understand the difference between authentication and authorization.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;The Analogy&lt;/b&gt;&lt;br /&gt;Here is an analogy, let&#39;s say that you want to get into a nightclub.&lt;br /&gt;&lt;br /&gt;First, you need to be &lt;b&gt;authenticated&lt;/b&gt;. By issuing a driver&#39;s license from the department of Motor Vehicles (analogous to the Identity Server), the state confirms your identity and generates a license, which includes data about you. The data includes information such as your name, your birth-date, your picture and so on. The token that you have been issued proves your identity.&lt;br /&gt;&lt;br /&gt;Next, you make your way to the club, with the license in hand. Once you arrive, the bouncer obtains your name from your license and makes an &lt;b&gt;authorization &lt;/b&gt;decision. “Is your name on the guest list?” The guest list acts as an approved claim in the system you want to access, which simply lists the people who are authorized to enter. If your name appears, then you are allowed access into the club.&lt;br /&gt;&lt;br /&gt;In this rather simplified analogy, there is a clear separation between the entity that performs authentication (the state government), and the entity that performs authorized (the club bouncer).&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Different protocols&lt;/b&gt;&lt;br /&gt;&lt;div&gt;Today the most common authentication protocols are OpenID Connect, WS-Federation and SAML2P. Where SAML2P are probably the most common protocol.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Microsoft Corporation has invested heavily into incorporating WS-Federation into its products. The most popular claim type for WS-Federation, ironically, is a SAML 1.1 Assertion. This leads people to think that WS-Federation and SAML can talk to each other. So when people talk about supporting SAML they really talking about support SAML claims inside WS-Federation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;OpenID Connect is only a couple years old, but is considered to be the future, since &lt;b&gt;it provides the most possibilities for modern applications&lt;/b&gt;. It was also designed to be more usable by native and mobile applications, and to be WebAPI friendly.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h4&gt;Architecture scenario&lt;/h4&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://3.bp.blogspot.com/-DExTLqqmjVU/Vx5r1cDcodI/AAAAAAAAArI/cQX-qpqcmdww5oA3a6J8Iu5jp3j-gkYDQCLcB/s1600/SSO-Arkitektur.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;440&quot; src=&quot;https://3.bp.blogspot.com/-DExTLqqmjVU/Vx5r1cDcodI/AAAAAAAAArI/cQX-qpqcmdww5oA3a6J8Iu5jp3j-gkYDQCLcB/s640/SSO-Arkitektur.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;Through e.g. a WebAPI you could get more profile data to enrich the information about the logged in user, instead of putting all kind of information into claims.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;IdentityServer3&lt;/b&gt;&lt;br /&gt;In this scenario, one of the key components is the use of IdentityServer3 to replace the authentication in Episerver or any website. The IdentityServer3 is a popular open source security token service framework written in .NET, that implements the OpenID Connect and OAuth2 protocols. It is used to authenticate users via single-sign-on and to secure WebAPIs. It can be used stand-alone or in conjunction with other identity providers, such as Google, Facebook, Azure AD, ADFS and others.&lt;br /&gt;&lt;br /&gt;IdentityServer3 supports different OpenId Connect flows that can be used in to communication between different types of clients.&lt;br /&gt;&lt;br /&gt;If you are going to have some form of communication between two systems that doesn’t involve human, e.g. web API’s, then you should look into using &quot;client credentials&quot; flow.&lt;br /&gt;&lt;br /&gt;Another one is the &quot;Hybrid&quot; flow. To avoid the users to reauthenticate every time they want to access a restricted area on the website you can use this flow, which contains the refresh token that’s used to obtain and renewed the identity token. I have written another blog post on how to connect Episerver and IdentityServer3 based on the OpenID Connect/OAuth2.0 protocol using the “Hybrid” flow. You can check that here:&lt;br /&gt;&lt;a href=&quot;http://sveinaandahl.blogspot.no/2016/04/how-to-setup-oauth20-integration.html&quot; target=&quot;_blank&quot;&gt;http://sveinaandahl.blogspot.no/2016/04/how-to-setup-oauth20-integration.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In some cases, where you will need to handle login with legacy systems it’s also possible to handle login screen on the website with the Resource Owner Flow, but this is usually not the recommended way. Depends on the goal and what kind of constrains you have.&lt;br /&gt;&lt;br /&gt;For&lt;b&gt; User Repository&lt;/b&gt;, IdentityServer3 supports both ASP.NET Identity 2.0 and MembershipReboot from Brock Allan. By using MembershipReboot you also have the ability to use nosql databases, like RavenDb and MongoDb.&lt;br /&gt;&lt;br /&gt;I have done migration for users from Membership provider, which is the default authentication system in Episerver, to ASP.NET Identity 2.0 and had no problems to validate old passwords afterwards. You can read about that here: &lt;br /&gt;&lt;a href=&quot;http://sveinaandahl.blogspot.no/2016/03/how-to-validate-old-passwords-when.html&quot; target=&quot;_blank&quot;&gt;http://sveinaandahl.blogspot.no/2016/03/how-to-validate-old-passwords-when.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;My experience is that ASP.NET Identity 2.0 need some “love” to perform just as good as the MembershipReboot do. &amp;nbsp;And that ASP.NET Identity 2.0 got less features then MembershipReboot. But both choices are reasonable.&lt;br /&gt;&lt;br /&gt;If a company has several brands, each with its own website, they might wish to customize the login screen for each brand. This is possible to do, to some degree with Identity Server. The screen dump below shows the login screen looks like default, customized with Norwegian language.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://1.bp.blogspot.com/-sdzKQJ7srKQ/VxTC13S0IcI/AAAAAAAAAqc/QbC0AotgR_ka49juYymDU1fcclmnWd17QCLcB/s1600/Login-Idsrv3.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;384&quot; src=&quot;https://1.bp.blogspot.com/-sdzKQJ7srKQ/VxTC13S0IcI/AAAAAAAAAqc/QbC0AotgR_ka49juYymDU1fcclmnWd17QCLcB/s640/Login-Idsrv3.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;Extensibility and customization&lt;/b&gt;&lt;br /&gt;In some cases, you e.g. want to be able to override the login process to validate other username than email, but also use phone number, member number and so on. Or maybe you want to validate if users exist and then populate claims from the CRM system during login process. Could also happened you want to be able verify that the user exists in the CRM system, before the user are allowed to register. &lt;br /&gt;&lt;br /&gt;Since IdentityServer3 is designed for extensibility and customization and allows applications to satisfy their custom security requirements you will be able to do that. But you should always be very careful how your stitching this together to avoid security breach in your system.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Scalability&lt;/b&gt;&lt;br /&gt;The IdentityServer3 is very scalable. The application is built in a way that setting it up in a load balanced environment is quite easy. Performance challenges is usually depended on what choices you have made when it comes to user repository and if you have extended and customized the login process in good way.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Links&lt;/b&gt;&lt;br /&gt;For those who use Xamarin to build mobile applications on iOS or Android. Here is an example how to integrate Xamarin with Identity Server:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/Xamarin&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://github.com/IdentityServer/IdentityServer3.Samples/tree/master/source/Xamarin&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you are interested in finding out more about IdentityServer3 it’s a good start to begin here:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://identityserver.github.io/Documentation/docsv2/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://identityserver.github.io/Documentation/docsv2/&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;For those who are interested, then Identity Server will also be supported for ASP.NET 5 when it’s launched.&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://www.blogger.com/.%20http://leastprivilege.com/2016/01/11/announcing-identityserver-for-asp-net-5-and-net-core/&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;http://leastprivilege.com/2016/01/11/announcing-identityserver-for-asp-net-5-and-net-core/&lt;/a&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2016/04/how-to-do-identity-and-access.html</guid>            <pubDate>Mon, 25 Apr 2016 21:23:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to validate old passwords when migrating from Membership provider to ASP.NET Identity in Episerver</title>            <link>http://sveinaandahl.blogspot.com/2016/03/how-to-validate-old-passwords-when.html</link>            <description>Wouldn’t be nice to be able to validate the old passwords when you migrate from Membership provider to ASP.NET Identity? This was one of my headaches in an earlier project, but here is the solution.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Prerequisite&amp;nbsp;&lt;/b&gt;&lt;br /&gt;The example in this post are based on the code from here:&amp;nbsp;&lt;a href=&quot;http://sveinaandahl.blogspot.no/2015/08/how-to-integrate-aspnet-identity-with.html&quot; target=&quot;_blank&quot;&gt;http://sveinaandahl.blogspot.no/2015/08/how-to-integrate-aspnet-identity-with.html&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Note!&lt;/b&gt;&lt;/div&gt;&lt;div&gt;One of the things you should check out first in the original Episerver solution&#39;s web.config. Here you will find the hash algorithm type that’s used in the Membership provider. In the example below you can see &#171;HMACSHA512&#187; is used.&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;From Web.config:&lt;/b&gt;&lt;/div&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt; &lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;membership&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;defaultProvider&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;SqlServerMembershipProvider&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;userIsOnlineTimeWindow&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;10&quot;&lt;/span&gt; &lt;span style=&quot;background-color: yellow;&quot;&gt;&lt;span class=&quot;attr&quot;&gt;hashAlgorithmType&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;HMACSHA512&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div&gt;&lt;br /&gt;The whole clue when you migrate the passwords is to put the hashed password together with the password format, that’s always 1, and the password salt. Then you put it into the Hashed Password field in the new database.&lt;br /&gt;&lt;br /&gt;e.g.: aspnet_Membership.Password+&#39;|&#39;+ 1 +&#39;|&#39;+aspnet_Membership.PasswordSalt&lt;br /&gt;&lt;br /&gt;In the User Manager code you override the PasswordHasher function. When you get a user that has a password with this type of password format use the original way to encrypt the passwords in Membership provider, or else you can use the base version of PasswordHasher. Use the same hash algorithm type that you used to create in the original solution.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;IdentityConfig.cs&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Override the Password hasher function.&lt;/div&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationUserManager : UserManager&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationUserManager(ApplicationUserStore store)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(store)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            PasswordHasher = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; MyPasswordHasher();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;MyPasswordHasher.cs&lt;/b&gt;&lt;br /&gt;Add a new class called MyPasswordHasher.cs &lt;br /&gt;&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Cryptography;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; MyPasswordHasher : PasswordHasher&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; HashPassword(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; password)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {          &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.HashPassword(password);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; PasswordVerificationResult VerifyHashedPassword(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; hashedPassword, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; providedPassword)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; passwordProperties = hashedPassword.Split(&lt;span class=&quot;str&quot;&gt;&#39;|&#39;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (passwordProperties.Length != 3)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.VerifyHashedPassword(hashedPassword, providedPassword);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; passwordHash = passwordProperties[0];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; passwordformat = 1;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; salt = passwordProperties[2];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (String.Equals(EncryptPassword(providedPassword, passwordformat, salt), passwordHash, StringComparison.CurrentCultureIgnoreCase))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; PasswordVerificationResult.SuccessRehashNeeded;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; PasswordVerificationResult.Failed;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; EncryptPassword(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; pass, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; passwordFormat, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; salt)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (passwordFormat == 0) &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; pass;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bIn = Encoding.Unicode.GetBytes(pass);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bSalt = Convert.FromBase64String(salt);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bRet = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (passwordFormat == 1)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {  &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                HashAlgorithm hm = HashAlgorithm.Create(&lt;span class=&quot;str&quot; style=&quot;background-color: yellow;&quot;&gt;&quot;HMACSHA512&quot;&lt;/span&gt;); &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (hm &lt;span class=&quot;kwrd&quot;&gt;is&lt;/span&gt; KeyedHashAlgorithm)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    KeyedHashAlgorithm kha = (KeyedHashAlgorithm)hm;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (kha.Key.Length == bSalt.Length)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        kha.Key = bSalt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (kha.Key.Length &amp;lt; bSalt.Length)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bKey = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[kha.Key.Length];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        Buffer.BlockCopy(bSalt, 0, bKey, 0, bKey.Length);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        kha.Key = bKey;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bKey = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[kha.Key.Length];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &lt;span class=&quot;kwrd&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; iter = 0; iter &amp;lt; bKey.Length; )&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; len = Math.Min(bSalt.Length, bKey.Length - iter);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            Buffer.BlockCopy(bSalt, 0, bKey, iter, len);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            iter += len;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        kha.Key = bKey;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    bRet = kha.ComputeHash(bIn);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] bAll = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[bSalt.Length + bIn.Length];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    bRet = hm.ComputeHash(bAll);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Convert.ToBase64String(bRet);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Migration of the database.&lt;/b&gt;&lt;br /&gt;Since the database is created by the Entity Framework the first time you run the Episerver application with ASP.NET Identity, I recommend you not to try to use any create tables in the migration script. Since this often end up being a corrupt database for the Entity Framework.&lt;br /&gt;&lt;br /&gt;The simple version would be just to do inserts on a existing database. The migration script could look something like the script below. Notice how the password format is set together.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;The script below is not well tested, but it gives you an idea how it could work.&lt;/div&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt; &lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;INSERT&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;INTO&lt;/span&gt; AspNetUsers(Id,Email,EmailConfirmed,PasswordHash,SecurityStamp,&lt;br /&gt;PhoneNumber,PhoneNumberConfirmed,TwoFactorEnabled,LockoutEndDateUtc,LockoutEnabled,&lt;br /&gt;AccessFailedCount,UserName)&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;SELECT&lt;/span&gt; aspnet_Users.UserId,aspnet_Membership.Email,&lt;span class=&quot;str&quot;&gt;&#39;true&#39;&lt;/span&gt;,&lt;br /&gt;(aspnet_Membership.Password+&lt;span class=&quot;str&quot;&gt;&#39;|&#39;&lt;/span&gt;+&lt;span class=&quot;kwrd&quot;&gt;CAST&lt;/span&gt;(aspnet_Membership.PasswordFormat &lt;span class=&quot;kwrd&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;varchar&lt;/span&gt;)+&lt;span class=&quot;str&quot;&gt;&#39;|&#39;&lt;/span&gt;+aspnet_Membership.PasswordSalt),&lt;br /&gt;NewID(),&lt;span class=&quot;kwrd&quot;&gt;NULL&lt;/span&gt;,&lt;span class=&quot;str&quot;&gt;&#39;false&#39;&lt;/span&gt;,&lt;span class=&quot;str&quot;&gt;&#39;true&#39;&lt;/span&gt;,aspnet_Membership.LastLockoutDate,&lt;span class=&quot;str&quot;&gt;&#39;true&#39;&lt;/span&gt;,&lt;span class=&quot;str&quot;&gt;&#39;0&#39;&lt;/span&gt;,aspnet_Users.UserName&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;FROM&lt;/span&gt; aspnet_Users&lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;LEFT&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;OUTER&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;JOIN&lt;/span&gt; aspnet_Membership &lt;span class=&quot;kwrd&quot;&gt;ON&lt;/span&gt; aspnet_Membership.ApplicationId = aspnet_Users.ApplicationId &lt;br /&gt;&lt;span class=&quot;kwrd&quot;&gt;AND&lt;/span&gt; aspnet_Users.UserId = aspnet_Membership.UserId;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;TIPS&lt;/b&gt;&lt;br /&gt;If you are going to run this script several times without getting duplicates you should probably look into using cursor scripts in sql. This way you would avoid inserting a user that&#39;s already migrated.&lt;br /&gt;&lt;br /&gt;Have fun!&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2016/03/how-to-validate-old-passwords-when.html</guid>            <pubDate>Mon, 14 Mar 2016 09:23:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>Tips for installing Episerver standard search with SSL</title>            <link>http://sveinaandahl.blogspot.com/2016/01/tips-for-installing-episerver-standard.html</link>            <description>I wrote a blog post on how to setup Episerver Standard Search more than three years ago. After getting some questions about how use of SSL together with Episerver standard search, I thought I should share some useful tips here. I noticed that several people have written about this topic earlier, so this is more like an add on to this.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;First of all, you should get the solution up and running &lt;b&gt;without&lt;/b&gt; SSL. You will find a guide how to do that from this blog:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: 13.65pt; margin-bottom: 3.0pt;&quot;&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&lt;a href=&quot;http://sveinaandahl.blogspot.no/2013/06/how-to-install-episerver-search-for.html&quot; target=&quot;_blank&quot;&gt;http://sveinaandahl.blogspot.no/2013/06/how-to-install-episerver-search-for.html&lt;/a&gt;&lt;/span&gt;&lt;span style=&quot;background-attachment: initial; background-clip: initial; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial; color: #444444; font-family: Arial, sans-serif; font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; line-height: 13.65pt; margin-bottom: 3.0pt;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background: white; margin-bottom: 3pt;&quot;&gt;&lt;span style=&quot;line-height: 18.2px;&quot;&gt;There are a two elements you will need to add to the web.config, when you want to add ssl support to your solution. Changes are marked with yellow background.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;line-height: 18.2px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;span style=&quot;line-height: 18.2px;&quot;&gt;&lt;b&gt;Web.config&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt; &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.serviceModel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;serviceHostingEnvironment&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;multipleSiteBindingsEnabled&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;bindings&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;webHttpBinding&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;binding&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;IndexingServiceCustomBinding&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxBufferPoolSize&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;1073741824&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;2147483647&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxBufferSize&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;2147483647&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;security&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Transport&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;              &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;transport&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;clientCredentialType&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;None&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;           &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;security&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;readerQuotas&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxStringContentLength&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;10000000&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;webHttpBinding&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;bindings&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.serviceModel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.search&lt;/span&gt; active=&quot;true&quot;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;namedIndexingServices&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;defaultService&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;serviceName&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;serviceName&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;baseUri&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;http&lt;span style=&quot;background-color: yellow;&quot;&gt;s&lt;/span&gt;://DNS-name/IndexingService/IndexingService.svc&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;accessKey&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;local&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;namedIndexingServices&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;searchResultFilter&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;defaultInclude&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;searchResultFilter&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.search&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;IIS&lt;/b&gt;&lt;br /&gt;In IIS you will need to add a https binding and perhaps remove the http. :-)&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-mlkLJz2L3is/VpZdTt7idSI/AAAAAAAAApM/62XJ5DVuaA0/s1600/SSL0.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-mlkLJz2L3is/VpZdTt7idSI/AAAAAAAAApM/62XJ5DVuaA0/s550/SSL0.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;If everything is working fine you should get up a web service in your browser from this url (including the https): https://YourDnsName/IndexingService/IndexingService.svc&lt;br /&gt;&lt;br /&gt;If not, you should read on. :-)&lt;br /&gt;&lt;br /&gt;&lt;b&gt;TIPS!&lt;/b&gt; &#171;HTTP Activation&#187; is a feature that is often forgot. So it&#39;s always smart to check if that&#39;s activated for the asp.net version you use in the project.&lt;br /&gt;&lt;br /&gt;My experience is that it’s usually two things with the setup that’s not correct, when using SSL together with standard search. One is the lack of knowledge about certificates and how to install them, and second is how to setup the IIS correct.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Different certificates&lt;/b&gt;&lt;br /&gt;The most used certificate types are &#171;Domain validated certificates&#187; and &#171;Extended validation certificates&#187;. The use of EV certificate can be easily spotted by that the url field in the browser get an &#171;green bar&#187; in the beginning. More and more sites has started to use these EV certificates.They usually cost little more and takes longer to order because of the validation process.&lt;br /&gt;&lt;br /&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;&lt;b&gt;&lt;i&gt;Extended Validation Certificate&lt;/i&gt;&lt;/b&gt;&lt;/blockquote&gt;&lt;blockquote class=&quot;tr_bq&quot;&gt;&lt;i&gt;EV certificates use the same encryption as domain validated certificates: The increase in security is due to the identity validation process, which is indicated inside the certificated by the policy identifier&lt;/i&gt;.&lt;/blockquote&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;i&gt;Ref: &lt;a href=&quot;https://en.wikipedia.org/wiki/Extended_Validation_Certificate&quot; target=&quot;_blank&quot;&gt;https://en.wikipedia.org/wiki/Extended_Validation_Certificate&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;Production environment&amp;nbsp;&lt;/b&gt;&lt;br /&gt;Before IIS8, there was an problem to have more than one certificate per server, since most server have only one IP address. Often this could be solve by using a SAN certificate that contain several domains.&lt;br /&gt;&lt;br /&gt;With Windows 2012 (IIS8) came a new feature called Server Name Identification (SNI), which made it possible to use several certificate on same IP.&lt;br /&gt;&lt;br /&gt;You can find more information on how to install this things here:&lt;br /&gt;&lt;br /&gt;Single Certificate and Multiple Certificates Using SNI (IIS8)&lt;br /&gt;&lt;a href=&quot;https://www.digicert.com/ssl-certificate-installation-microsoft-iis-8.htm&quot; target=&quot;_blank&quot;&gt;https://www.digicert.com/ssl-certificate-installation-microsoft-iis-8.htm&lt;/a&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;SAN Ceritifcate ( Multi-Domain )&lt;/div&gt;&lt;div&gt;&lt;a href=&quot;https://www.digicert.com/subject-alternative-name.htm&quot; target=&quot;_blank&quot;&gt;https://www.digicert.com/subject-alternative-name.htm&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Development environment&lt;/b&gt;&lt;br /&gt;In development we usually just create a self-signed certificate. When you create this in IIS they are usually &#171;Issued To&#187; your computer name. What you write in as Friendly name doesn’t really mater.&lt;br /&gt;So, if you want to avoid to getting a certificate error when you run your site in the browser you should use your machine name as localhost name.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;TIPS!&amp;nbsp;&lt;/b&gt;If you only are using one certificate you put the certificate into &#171;Personal&#187;. If you are going to use SNI, you must add it to &#171;Web Hosting&#187;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-hgvIXEtRHRc/VpZWuw61EbI/AAAAAAAAAo8/p_Q-5czUXfw/s1600/ssl2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-hgvIXEtRHRc/VpZWuw61EbI/AAAAAAAAAo8/p_Q-5czUXfw/s550/ssl2.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-kJBd9xQPY2k/VpZWuymwJbI/AAAAAAAAAos/wP_33lEASZk/s1600/SSL1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-kJBd9xQPY2k/VpZWuymwJbI/AAAAAAAAAos/wP_33lEASZk/s550/SSL1.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;How to access the&amp;nbsp;certificate&amp;nbsp;&lt;/b&gt;&lt;br /&gt;If you get access denied in the log file, here is a way to fix that. After you have create the certificate to the Personal folder, then type &quot;MMC&quot; in Windows search and open it up.(got an icon of a red tool box)&lt;br /&gt;&lt;br /&gt;Then goto FILE -&amp;gt; Add/Remove Snap-in. -&amp;gt; Select Certificates -&amp;gt; click Add-&amp;gt; Select Computer account -&amp;gt; Local Computer -&amp;gt; Finished -&amp;gt; Ok.&lt;br /&gt;&lt;br /&gt;Then open up Certificates -&amp;gt; Personal. Here you will find the certificate you have created or installed earlier.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-ALeeJILE1XE/VpZWu-KSYxI/AAAAAAAAAow/J7DqS5quyBA/s1600/ssl3.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-ALeeJILE1XE/VpZWu-KSYxI/AAAAAAAAAow/J7DqS5quyBA/s550/ssl3.png&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;Add Permissions to the certificate&lt;/b&gt;&lt;br /&gt;Right click on the certificate(marked blue on picture above) -&amp;gt; All tasks -&amp;gt; Manage Private Keys -&amp;gt; Add &quot;Network Service&quot; user -&amp;gt; Remove &#171;Full control&#187; (only read is necessary) -&amp;gt; OK&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-LA0ggiE3mzY/VpZWvWrFVLI/AAAAAAAAAo0/MPXnlo9ej1g/s1600/ssl4.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-LA0ggiE3mzY/VpZWvWrFVLI/AAAAAAAAAo0/MPXnlo9ej1g/s320/ssl4.JPG&quot; width=&quot;257&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;IIS&lt;/b&gt;&lt;br /&gt;Now add &#171;Network Service&#187; to the Application Pool to the site you use in IIS for the site with SSL. This will give the App pool identity access to both certificate and the site.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-Mt8TPYwGA7o/VpZWvR-w_lI/AAAAAAAAAo4/Di26c5sY-kg/s1600/ssl5.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-Mt8TPYwGA7o/VpZWvR-w_lI/AAAAAAAAAo4/Di26c5sY-kg/s550/ssl5.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Happy configuring! :-)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2016/01/tips-for-installing-episerver-standard.html</guid>            <pubDate>Wed, 13 Jan 2016 16:10:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to improve performance with ASP.NET Identity and Episerver</title>            <link>http://sveinaandahl.blogspot.com/2015/12/how-to-improve-performance-with-aspnet.html</link>            <description>I have written a few blog posts now about how to implement ASP.NET Identity in Episerver. If you use the ASP.NET Identity data model out of the box, you could run into some performance issues with large quantity. With a few tricks you could optimize the data model and improve the performance a lot. I have tested this changes with a database that contains more than 400 thousand users. The performance improved with more than 10 times.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;When it comes to both performance and security it’s important that the database isn’t running on the same server as the CMS.&lt;/div&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;Important note!&lt;/b&gt;&amp;nbsp;If you already got a database model up and running and apply this changes you would need to do a migration to new database model. Here is some reference on how to fix that if you run into this problem:&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application&quot; target=&quot;_blank&quot;&gt;http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;h3&gt;Prerequisite&amp;nbsp;&lt;/h3&gt;The example in this post are based on the code from here: &lt;a href=&quot;http://sveinaandahl.blogspot.no/2015/08/how-to-integrate-aspnet-identity-with.html&quot; target=&quot;_blank&quot;&gt;http://sveinaandahl.blogspot.no/2015/08/how-to-integrate-aspnet-identity-with.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Database model&lt;/h3&gt;&lt;div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;It was several elements I found during the analyze that could improve the performance, but here are a few easy fixes.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;It’s important that Datatypes in the database isn’t using &amp;nbsp;MAX, e.g. NVARCHAR&amp;lt;MAX&amp;gt;. It’s actually better to set a large number. SQL will not index datatype the contains the datatype MAX.&lt;/li&gt;&lt;li&gt;When this is fixed. You can add index on selected tables. By doing this the request dropped from 200 milliseconds to 30.&amp;nbsp;&lt;/li&gt;&lt;li&gt;Another effect by adding indexs is that the SQL server will be steady, even if the CMS frontend server gets a lot of request.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot;&gt;Most of this changes can be done through Entity framework. All the changes you want to apply to the data model can implemented in the OnModelCreating function. &amp;nbsp;Here you can change the datatype and add index types that will be used a lot.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;b&gt;Update Models/Account/ApplicationUser.cs with this code&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.ComponentModel.DataAnnotations.Schema;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Data.Entity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Data.Entity.Infrastructure.Annotations;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity.EntityFramework;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Models.Account&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationUser : IdentityUser&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; async Task&amp;lt;ClaimsIdentity&amp;gt; GenerateUserIdentityAsync(UserManager&amp;lt;ApplicationUser&amp;gt; manager)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; userIdentity = await manager.CreateIdentityAsync(&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;, DefaultAuthenticationTypes.ApplicationCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Add custom user claims here&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; userIdentity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; MyClaims : IdentityUserClaim&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationDbContext : IdentityDbContext&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationDbContext()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(&lt;span class=&quot;str&quot;&gt;&quot;EcfSqlConnection&quot;&lt;/span&gt;, throwIfV1Schema: &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            Database.SetInitializer&amp;lt;ApplicationDbContext&amp;gt;(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DropCreateDatabaseIfModelChanges&amp;lt;ApplicationDbContext&amp;gt;());&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; ApplicationDbContext Create()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationDbContext();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span style=&quot;background-color: yellow;&quot;&gt;&lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; OnModelCreating(DbModelBuilder modelBuilder)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.OnModelCreating(modelBuilder);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//Shorten length on existing datatypes =&amp;gt; improve performance&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            modelBuilder.Entity&amp;lt;ApplicationUser&amp;gt;().Property(u =&amp;gt; u.PhoneNumber).HasMaxLength(20);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            modelBuilder.Entity&amp;lt;ApplicationUser&amp;gt;().Property(u =&amp;gt; u.PasswordHash).HasMaxLength(1024);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            modelBuilder.Entity&amp;lt;ApplicationUser&amp;gt;().Property(u =&amp;gt; u.SecurityStamp).HasMaxLength(1024);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            modelBuilder.Entity&amp;lt;MyClaims&amp;gt;().Property(u =&amp;gt; u.ClaimType).HasMaxLength(512);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            modelBuilder.Entity&amp;lt;MyClaims&amp;gt;().Property(u =&amp;gt; u.ClaimValue).HasMaxLength(512);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//Indexing important datatypes. =&amp;gt; improve performance&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            modelBuilder.Entity&amp;lt;ApplicationUser&amp;gt;().Property(u =&amp;gt; u.Email).HasColumnAnnotation(&lt;span class=&quot;str&quot;&gt;&quot;Index&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; IndexAnnotation(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; IndexAttribute()));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;Happy coding!</description>            <guid>http://sveinaandahl.blogspot.com/2015/12/how-to-improve-performance-with-aspnet.html</guid>            <pubDate>Fri, 18 Dec 2015 11:36:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to login to EPiServer with Facebook</title>            <link>http://sveinaandahl.blogspot.com/2015/12/how-to-login-to-episerver-with-facebook.html</link>            <description>Wouldn&#39;t it be great to be able to login with another Identity Provider, e.g. Facebook, in your Episerver solution? Which could giving you the ability to extract Facebook information from you users. In the picture below, you can see your Facebook picture and username displayed in the header on the standard Episerver Alloy demo after login.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-BuvYR9ja3l4/Vldtk1RbuWI/AAAAAAAAAm8/n_GkX_6OP5w/s1600/4-LoggedinFacebook.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-BuvYR9ja3l4/Vldtk1RbuWI/AAAAAAAAAm8/n_GkX_6OP5w/s550/4-LoggedinFacebook.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;b&gt;Prerequisite&amp;nbsp;&lt;/b&gt;&lt;br /&gt;First, you will need to create a login based on the ASP.NET Identity instead of Membership provider. You find how to do that &lt;a href=&quot;http://sveinaandahl.blogspot.no/2015/08/how-to-integrate-aspnet-identity-with.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;. This example should work with EPiServer version 8 from 14 November 2014 and up. However, I recommend updating to the latest version.   &lt;br /&gt;&lt;br /&gt;&lt;b&gt;Create a connection with Facebook&lt;/b&gt;&lt;br /&gt;You will need to setup an App on Facebook to be able to create a connection.  Go to &lt;a href=&quot;https://developers.facebook.com/apps&quot; target=&quot;_blank&quot;&gt;https://developers.facebook.com/apps&lt;/a&gt; to do that. Here is a good link to how to setup the connection step-by-step, &lt;a href=&quot;http://www.oauthforaspnet.com/providers/facebook/&quot; target=&quot;_blank&quot;&gt;http://www.oauthforaspnet.com/providers/facebook/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Tips!&lt;/b&gt; Remember that after you have create an App, you can add a platform. In this case, you would add a “website”. Since this is a test case, you can add a localhost address here. Notice the App ID and App Secret, which you will need later on.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-jsdCic-mdLg/Vldu9Op6lWI/AAAAAAAAAnI/_j_kWN_1cwQ/s1600/FacebookApp.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-jsdCic-mdLg/Vldu9Op6lWI/AAAAAAAAAnI/_j_kWN_1cwQ/s550/FacebookApp.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Necessary nuget packages&lt;/b&gt;&lt;br /&gt;You will need at least one nuget package to be able to create this connection in your project.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Install-Package Microsoft.Owin.Security.Facebook&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;Other nuget packages that could come handy later on:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Install-Package Microsoft.Owin.Security.Google&amp;nbsp;&lt;/li&gt;&lt;li&gt;Install-Package Microsoft.Owin.Security.MicrosoftAccount&amp;nbsp;&lt;/li&gt;&lt;li&gt;Install-Package Microsoft.Owin.Security.Twitter&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;If you want to extract more information from Facebook, you will need to install this one too.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Install-Package Facebook&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Startup.cs&lt;/b&gt;&lt;br /&gt;If you only want the plain login you don’t need specify anything more than the following lines in the Startup.cs. &lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; facebookOptions = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; FacebookAuthenticationOptions();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   facebookOptions.AppId = &lt;span class=&quot;str&quot;&gt;&quot;xxxxxxxxxxxxxxxx&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   facebookOptions.AppSecret = &lt;span class=&quot;str&quot;&gt;&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   app.UseFacebookAuthentication(facebookOptions);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;However, if you want to extract more information through scopes and token it could look something like this: &lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; facebookOptions = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; FacebookAuthenticationOptions();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    facebookOptions.Scope.Add(&lt;span class=&quot;str&quot;&gt;&quot;email&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    facebookOptions.AppId = &lt;span class=&quot;str&quot;&gt;&quot;xxxxxxxxxxxxxxxx&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    facebookOptions.AppSecret = &lt;span class=&quot;str&quot;&gt;&quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    facebookOptions.Provider = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; FacebookAuthenticationProvider()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        OnAuthenticated = async context =&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//Get the access token from FB and store it in the database and use FacebookC# SDK to get more information about the user&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            context.Identity.AddClaim(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; System.Security.Claims.Claim(&lt;span class=&quot;str&quot;&gt;&quot;FacebookAccessToken&quot;&lt;/span&gt;, context.AccessToken));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    };&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    facebookOptions.SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    app.UseFacebookAuthentication(facebookOptions);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Extend the login screen&lt;/b&gt;&lt;br /&gt;Since I already have styled the login screen in Episerver style, I have just extended it with a partial view to be able to login with Facebook.   &lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-o2Y-9eFnI3M/Vld05FuGpBI/AAAAAAAAAnY/TWmG5vyLa6g/s1600/4-loginWithProvider.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-o2Y-9eFnI3M/Vld05FuGpBI/AAAAAAAAAnY/TWmG5vyLa6g/s550/4-loginWithProvider.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Add these views to the solution.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Account/Login.cshtml&lt;/b&gt;&lt;br /&gt;Extend login with partial view to login with facebook and other identity providers.&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Optimization&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@model TestSite.Models.Account.LoginViewModel&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    ViewBag.Title = &lt;span class=&quot;str&quot;&gt;&quot;Log in&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    Layout = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;meta http-equiv=&lt;span class=&quot;str&quot;&gt;&quot;X-UA-Compatible&quot;&lt;/span&gt; content=&lt;span class=&quot;str&quot;&gt;&quot;IE=EmulateIE7&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; href=&lt;span class=&quot;str&quot;&gt;&quot;/util/styles/login.css&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;meta name=&lt;span class=&quot;str&quot;&gt;&quot;robots&quot;&lt;/span&gt; content=&lt;span class=&quot;str&quot;&gt;&quot;noindex,nofollow&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link href=&lt;span class=&quot;str&quot;&gt;&quot;../App_Themes/Default/Styles/system.css&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link href=&lt;span class=&quot;str&quot;&gt;&quot;../App_Themes/Default/Styles/ToolButton.css&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;body &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginBody&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginContainer&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginTop&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginMiddle&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginContent&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginLogo&quot;&lt;/span&gt;&amp;gt;@ViewBag.Title.&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginForm&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;h1&amp;gt;&amp;lt;span style=&lt;span class=&quot;str&quot;&gt;&quot;color: Red;&quot;&lt;/span&gt;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_ValidationSummary1&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-credentialsContainer&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            @&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; (Html.BeginForm(&lt;span class=&quot;str&quot;&gt;&quot;Login&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;form-horizontal&quot;&lt;/span&gt;, role = &lt;span class=&quot;str&quot;&gt;&quot;form&quot;&lt;/span&gt; }))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                @Html.AntiForgeryToken()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                @Html.ValidationSummary(&lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-float-left&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    @Html.LabelFor(m =&amp;gt; m.UserName, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;episize80&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.TextBoxFor(m =&amp;gt; m.UserName, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;epi-inputText&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.ValidationMessageFor(m =&amp;gt; m.UserName)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_RequiredFieldValidator1&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&#173;&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-float-left&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    @Html.LabelFor(m =&amp;gt; m.Password, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;episize80&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.PasswordFor(m =&amp;gt; m.Password, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;epi-inputText&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.ValidationMessageFor(m =&amp;gt; m.Password)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_RequiredFieldValidator2&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&#173;&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button-container epi-float-left&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        &amp;lt;span &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button-child&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                            &amp;lt;input type=&lt;span class=&quot;str&quot;&gt;&quot;submit&quot;&lt;/span&gt; value=&lt;span class=&quot;str&quot;&gt;&quot;Log in&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button-child-item&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        &amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-checkbox-container&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-checkbox&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.CheckBoxFor(m =&amp;gt; m.RememberMe)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.LabelFor(m =&amp;gt; m.RememberMe)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginBottom&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-credentialsContainer&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;margin-left: 30px; margin-bottom: 10px;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                @Html.Partial(&lt;span class=&quot;str&quot;&gt;&quot;_ExternalLoginsListPartial&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; TestSite.Models.Account.ExternalLoginViewModel() { Action = &lt;span class=&quot;str&quot;&gt;&quot;ExternalLogin&quot;&lt;/span&gt;, ReturnUrl = ViewBag.ReturnUrl })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;/body&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@section Scripts {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    @Scripts.Render(&lt;span class=&quot;str&quot;&gt;&quot;~/bundles/jqueryval&quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Account/_ExternalLoginsListPartial.cshtml&lt;/b&gt;&lt;br /&gt;List out the identity providers that has been configured.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@model TestSite.Models.Account.ExternalLoginViewModel&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;b&amp;gt;Log on &lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; these Providers.&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; loginProviders = Context.GetOwinContext().Authentication.GetExternalAuthenticationTypes();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (loginProviders.Count() == 0)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;p&amp;gt;There are no external authentication services configured. &amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; action = Model.Action;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl = Model.ReturnUrl;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; (Html.BeginForm(action, &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { ReturnUrl = returnUrl }))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            @Html.AntiForgeryToken()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;socialLoginList&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;p&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    @&lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (AuthenticationDescription p &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; loginProviders)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;button type=&lt;span class=&quot;str&quot;&gt;&quot;submit&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;btn btn-default&quot;&lt;/span&gt; id=&lt;span class=&quot;str&quot;&gt;&quot;@p.AuthenticationType&quot;&lt;/span&gt; name=&lt;span class=&quot;str&quot;&gt;&quot;provider&quot;&lt;/span&gt; value=&lt;span class=&quot;str&quot;&gt;&quot;@p.AuthenticationType&quot;&lt;/span&gt; title=&lt;span class=&quot;str&quot;&gt;&quot;Log in using your @p.Caption account&quot;&lt;/span&gt;&amp;gt;@p.AuthenticationType&amp;lt;/button&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Account/ExternalLoginConfirmation.cshtml&lt;/b&gt;&lt;br /&gt;Confirmation view after the user have logged in to facebook or other identity providers.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Optimization&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@model TestSite.Models.Account.ExternalLoginConfirmationViewModel&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    ViewBag.Title = &lt;span class=&quot;str&quot;&gt;&quot;Register&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    Layout = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;meta http-equiv=&lt;span class=&quot;str&quot;&gt;&quot;X-UA-Compatible&quot;&lt;/span&gt; content=&lt;span class=&quot;str&quot;&gt;&quot;IE=EmulateIE7&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; href=&lt;span class=&quot;str&quot;&gt;&quot;/util/styles/login.css&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;meta name=&lt;span class=&quot;str&quot;&gt;&quot;robots&quot;&lt;/span&gt; content=&lt;span class=&quot;str&quot;&gt;&quot;noindex,nofollow&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link href=&lt;span class=&quot;str&quot;&gt;&quot;../App_Themes/Default/Styles/system.css&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link href=&lt;span class=&quot;str&quot;&gt;&quot;../App_Themes/Default/Styles/ToolButton.css&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;body &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginBody&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginContainer&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginTop&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginMiddle&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginContent&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginLogo&quot;&lt;/span&gt;&amp;gt;@ViewBag.Title.&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;h3&amp;gt;Associate your @ViewBag.LoginProvider account.&amp;lt;/h3&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginForm&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;h1&amp;gt;&amp;lt;span style=&lt;span class=&quot;str&quot;&gt;&quot;color: Red;&quot;&lt;/span&gt;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_ValidationSummary1&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-credentialsContainer&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            @&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; (Html.BeginForm(&lt;span class=&quot;str&quot;&gt;&quot;ExternalLoginConfirmation&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;form-horizontal&quot;&lt;/span&gt;, role = &lt;span class=&quot;str&quot;&gt;&quot;form&quot;&lt;/span&gt; }))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                @Html.AntiForgeryToken()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;h4&amp;gt;Association Form&amp;lt;/h4&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;hr /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                @Html.ValidationSummary(&lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;p &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;text-info&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    You&#39;ve successfully authenticated with &amp;lt;strong&amp;gt;@ViewBag.LoginProvider&amp;lt;/strong&amp;gt;.&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    Please enter a user name &lt;span class=&quot;kwrd&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt; site below and click the Register button to finish&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    logging &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt;.&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;form-group&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    @Html.LabelFor(m =&amp;gt; m.UserName, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;col-md-2 control-label&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;col-md-10&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.TextBoxFor(m =&amp;gt; m.UserName, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;form-control&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.ValidationMessageFor(m =&amp;gt; m.UserName)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;form-group&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;col-md-offset-2 col-md-10&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        &amp;lt;input type=&lt;span class=&quot;str&quot;&gt;&quot;submit&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;btn btn-default&quot;&lt;/span&gt; value=&lt;span class=&quot;str&quot;&gt;&quot;Register&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginBottom&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    @section Scripts {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        @Scripts.Render(&lt;span class=&quot;str&quot;&gt;&quot;~/bundles/jqueryval&quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Account/ExternalLoginFailure.cshtml&lt;/b&gt;&lt;br /&gt;This view can be extended more with layout.&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    ViewBag.Title = &lt;span class=&quot;str&quot;&gt;&quot;Login Failure&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    Layout = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;h2&amp;gt;@ViewBag.Title.&amp;lt;/h2&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;h3 &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;text-error&quot;&lt;/span&gt;&amp;gt;Unsuccessful login with service.&amp;lt;/h3&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Add this line in the Header.cshtml&lt;/b&gt;&lt;br /&gt;Add this code snippet into the header view to render out picture and name of user.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      @{Html.RenderAction(&lt;span class=&quot;str&quot;&gt;&quot;_UserPartial&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;);}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Account/_UserPartial.cshtml&lt;/b&gt;&lt;br /&gt;Display the user picture from facebook and name.&lt;br /&gt;&lt;br /&gt;&amp;lt;div&amp;gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    @&lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;.IsNullOrEmpty(ViewBag.ProviderKey))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;img src=@Url.Content(&lt;span class=&quot;str&quot;&gt;&quot;https://graph.facebook.com/&quot;&lt;/span&gt; + ViewBag.ProviderKey + &lt;span class=&quot;str&quot;&gt;&quot;/picture?type=small&quot;&lt;/span&gt;) alt=&lt;span class=&quot;str&quot;&gt;&quot;@ViewBag.UserName&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;h3&amp;gt;@ViewBag.UserName&amp;lt;/h3&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Add these code lines in the Models/Account/AccountViewModels.cs&lt;/b&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ExternalLoginViewModel&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Action { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; ReturnUrl { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Add these code lines in the Controllers/AccountController.cs&lt;/b&gt;&lt;br /&gt;You don&#39;t need to add the StoreFacebookAuthToken if you aren&#39;t going to use facebook data in your solution. It also contain code that would add the facebook user to a Episerver role.&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;       &lt;span class=&quot;rem&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// POST: /Account/ExternalLogin&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [HttpPost]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [AllowAnonymous]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [ValidateAntiForgeryToken]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult ExternalLogin(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; provider, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Request a redirect to the external login provider&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ChallengeResult(provider,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                Url.Action(&lt;span class=&quot;str&quot;&gt;&quot;ExternalLoginCallback&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { ReturnUrl = returnUrl }));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// GET: /Account/ExternalLoginCallback&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [AllowAnonymous]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; async Task&amp;lt;ActionResult&amp;gt; ExternalLoginCallback(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (loginInfo == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RedirectToAction(&lt;span class=&quot;str&quot;&gt;&quot;Login&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Sign in the user with this external login provider if the user already has a login&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; user = await UserManager.FindAsync(loginInfo.Login);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (user != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;rem&quot;&gt;//Save the FacebookToken in the database if not already there&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                await StoreFacebookAuthToken(user);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                await SignInAsync(user, &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RedirectToLocal(returnUrl);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// If the user does not have an account, then prompt the user to create an account&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            ViewBag.ReturnUrl = returnUrl;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            ViewBag.LoginProvider = loginInfo.Login.LoginProvider;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View(&lt;span class=&quot;str&quot;&gt;&quot;ExternalLoginConfirmation&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ExternalLoginConfirmationViewModel { UserName = loginInfo.DefaultUserName });&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; async Task StoreFacebookAuthToken(ApplicationUser user)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; claimsIdentity = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (claimsIdentity != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;rem&quot;&gt;// Retrieve the existing claims for the user and add the FacebookAccessTokenClaim&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; currentClaims = await UserManager.GetClaimsAsync(user.Id);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; facebookAccessToken = claimsIdentity.FindAll(&lt;span class=&quot;str&quot;&gt;&quot;FacebookAccessToken&quot;&lt;/span&gt;).First();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!currentClaims.Any())&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    await UserManager.AddClaimAsync(user.Id, facebookAccessToken);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;rem&quot;&gt;//NB! These lines will add the user to the facebookgroup (role)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; assingedRoles = await UserManager.GetRolesAsync(user.Id);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!assingedRoles.Contains(&lt;span class=&quot;str&quot;&gt;&quot;WebAdmins&quot;&lt;/span&gt;) || !assingedRoles.Contains(&lt;span class=&quot;str&quot;&gt;&quot;WebEditors&quot;&lt;/span&gt;) || !assingedRoles.Contains(&lt;span class=&quot;str&quot;&gt;&quot;FacebookGroup&quot;&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    await UserManager.AddToRoleAsync(user.Id, &lt;span class=&quot;str&quot;&gt;&quot;FacebookGroup&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// POST: /Account/ExternalLoginConfirmation&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [HttpPost]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [AllowAnonymous]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [ValidateAntiForgeryToken]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; async Task&amp;lt;ActionResult&amp;gt; ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (User.Identity.IsAuthenticated)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View(model); &lt;span class=&quot;rem&quot;&gt;//ERROR?&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (ModelState.IsValid)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;rem&quot;&gt;// Get the information about the user from the external login provider&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; info = await AuthenticationManager.GetExternalLoginInfoAsync();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (info == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View(&lt;span class=&quot;str&quot;&gt;&quot;ExternalLoginFailure&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; user = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationUser { UserName = model.UserName };&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; result = await UserManager.CreateAsync(user);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (result.Succeeded)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    result = await UserManager.AddLoginAsync(user.Id, info.Login);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (result.Succeeded)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        await StoreFacebookAuthToken(user);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        await SignInAsync(user, &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RedirectToLocal(returnUrl);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                AddErrors(result);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            ViewBag.ReturnUrl = returnUrl;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View(model);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [AllowAnonymous]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult _UserPartial()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; userId = User.Identity.GetUserId();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;.IsNullOrEmpty(userId))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; claimsforUser = UserManager.GetClaims(userId);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                Claim firstOrDefault = claimsforUser.FirstOrDefault(x =&amp;gt; x.Type == &lt;span class=&quot;str&quot;&gt;&quot;FacebookAccessToken&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (firstOrDefault != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; accessToken = firstOrDefault.Value;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; fb = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; FacebookClient(accessToken);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    dynamic myInfo = fb.Get(&lt;span class=&quot;str&quot;&gt;&quot;me?fields=first_name,last_name,id&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    ViewBag.ProviderKey = myInfo.id;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    ViewBag.UserName = myInfo.first_name + &lt;span class=&quot;str&quot;&gt;&quot; &quot;&lt;/span&gt; + myInfo.last_name;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; user = await UserManager.FindByIdAsync(userId);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    ViewBag.UserName = user.UserName;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; PartialView();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;       &lt;span class=&quot;rem&quot;&gt;// Used for XSRF protection when adding external logins&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; XsrfKey = &lt;span class=&quot;str&quot;&gt;&quot;XsrfId&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ChallengeResult : HttpUnauthorizedResult&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ChallengeResult(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; provider, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; redirectUri) : &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;(provider, redirectUri, &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ChallengeResult(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; provider, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; redirectUri, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; userId)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                LoginProvider = provider;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                RedirectUri = redirectUri;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                UserId = userId;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; LoginProvider { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; RedirectUri { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; UserId { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; ExecuteResult(ControllerContext context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; properties = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AuthenticationProperties { RedirectUri = RedirectUri };&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (UserId != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    properties.Dictionary[XsrfKey] = UserId;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; AddErrors(IdentityResult result)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;foreach&lt;/span&gt; (&lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; error &lt;span class=&quot;kwrd&quot;&gt;in&lt;/span&gt; result.Errors)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                ModelState.AddModelError(&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;, error);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;b&gt;Testing the solution&lt;/b&gt;&lt;br /&gt;So after all is implemented and compiled you will come to a facebook login screen after you hit the &quot;facebook&quot; button on the episerver login screen.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-qL9cU62bvUU/Vld5orb4fHI/AAAAAAAAAnk/XQs2_DKk8Vs/s1600/FacebookLoginScreen.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-qL9cU62bvUU/Vld5orb4fHI/AAAAAAAAAnk/XQs2_DKk8Vs/s550/FacebookLoginScreen.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;After you have logged in you get a form where you can register the user in the local storage, but then without the password. &lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-uQX9QL6HELA/Vld6JaGTdeI/AAAAAAAAAnw/ggahZg0iUzI/s1600/FacebookRegisterScreen.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-uQX9QL6HELA/Vld6JaGTdeI/AAAAAAAAAnw/ggahZg0iUzI/s550/FacebookRegisterScreen.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;After hitting the registration button you will return to the start screen where the facebook picture and name is displayed.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Database&lt;/b&gt;&lt;br /&gt;If you look in the Identity database after you have register, you will notice the password is set to null on the facebook user.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-DfNJPgL972M/Vld7GnaQIbI/AAAAAAAAAn8/ubEp2GdmUSk/s1600/FacebookSQL2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-DfNJPgL972M/Vld7GnaQIbI/AAAAAAAAAn8/ubEp2GdmUSk/s550/FacebookSQL2.JPG&quot; width=&quot;550&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Okey. That&#39;s it. Happy coding!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;References&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;http://www.asp.net/web-api/overview/security/external-authentication-services&quot;&gt;http://www.asp.net/web-api/overview/security/external-authentication-services&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href=&quot;http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx&quot;&gt;http://blogs.msdn.com/b/webdev/archive/2013/10/16/get-more-information-from-social-providers-used-in-the-vs-2013-project-templates.aspx&lt;/a&gt;&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2015/12/how-to-login-to-episerver-with-facebook.html</guid>            <pubDate>Thu, 03 Dec 2015 11:11:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to fix the roles in EPiServer when using ASP.NET Identity</title>            <link>http://sveinaandahl.blogspot.com/2015/11/how-to-fix-roles-in-episerver-when.html</link>            <description>&lt;br /&gt;&lt;br /&gt;If you go into admin in EPiServer and then &quot;Set Access Rights for&quot;, you will fail to choose your Identity 2.0 roles. Reason for this is that the Access Rights GUI in EPiServer are closely connected to the old membership provider, which you disable when you implement the ASP.NET Identity.&lt;br /&gt;&lt;br /&gt;After a short brainstorm with my colleague Roger Nesheim, it became quite clear that the quickest way to fix this legacy problem was to use Dependency Injection and Inversion of Control. StructureMap is a DI/IOC tool exclusively for .NET programming, which we will use in this EPiServer projects. It helps in achieving looser coupling among classes and their dependencies.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;Edit:&lt;/b&gt;&lt;br /&gt;As Per suggested in the comment field, it&#39;s also possible to to implement this using built in provider instead of using StructureMap. So by add the following code in web.config and add the&amp;nbsp;IdentitySecurityEntityProvider.cs to the project it will also work. Thanks :-)&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.framework&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;securityEntity&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;IdentityProvider&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;TestSite.Business.AccessRights.IdentitySecurityEntityProvider, TestSite&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;securityEntity&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;appData&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;basePath&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;App_Data&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;scanAssembly&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;forceBinFolderScan&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;virtualRoles&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;addClaims&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3&gt;Solution&lt;/h3&gt;&lt;div&gt;First you need to setup the DI/IOC to override the “SecurityEntityProvider” and replace it with “IdentitySecurityEntityProvider” class. The setup below show how to do that.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;ServiceLocationConfiguration.cs&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Security;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; StructureMap;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; TestSite.Business.AccessRights;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Business.ServiceLocation&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ServiceLocationConfiguration&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; Action&amp;lt;ConfigurationExpression&amp;gt; Current&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; configuration =&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    configuration.For&amp;lt;&lt;span style=&quot;background-color: yellow;&quot;&gt;SecurityEntityProvider&lt;/span&gt;&amp;gt;().Use(() =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span style=&quot;background-color: yellow;&quot;&gt;IdentitySecurityEntityProvider&lt;/span&gt;());&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                };&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;b&gt;DependenciesInitializationModule.cs&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Framework;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Framework.Initialization;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.ServiceLocation;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Business.ServiceLocation&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    [InitializableModule]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    [ModuleDependency(&lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(ServiceContainerInitialization))]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; DependenciesInitializationModule : IConfigurableModule&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Initialize(InitializationEngine context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Preload(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;[] parameters) { }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Uninitialize(InitializationEngine context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//Add uninitialization logic&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; ConfigureContainer(ServiceConfigurationContext context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            context.Container.Configure(ServiceLocationConfiguration.Current);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Then you will need to override the different Search functions with new code to handle the communication with the ASP.NET Identity database. When this is in place the access rights with users and group will work as it used to.&lt;br /&gt;Disclaimer: The code isn&#39;t tested on large database with a lot of users and groups.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;IdentitySecurityEntityProvider.cs&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Security;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; TestSite.Models.Account;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Business.AccessRights&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; IdentitySecurityEntityProvider : PagingSupportingSecurityEntityProvider&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;readonly&lt;/span&gt; ApplicationDbContext _db = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationDbContext();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; IEnumerable&amp;lt;&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;&amp;gt; GetRolesForUser(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; userName)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; theUser = _db.Users.FirstOrDefault(u =&amp;gt; u.UserName.Equals(userName, StringComparison.CurrentCultureIgnoreCase));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; theUser == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt; ? Enumerable.Empty&amp;lt;&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;&amp;gt;() : theUser.Roles.Select(role =&amp;gt; _db.Roles.Find(role.RoleId).Name.ToString()).AsEnumerable();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; IEnumerable&amp;lt;SecurityEntity&amp;gt; Search(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; partOfValue, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; claimType)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; totalCount;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.Search(partOfValue, claimType, 0, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;.MaxValue, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; totalCount);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; IEnumerable&amp;lt;SecurityEntity&amp;gt; Search(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; partOfValue, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; claimType, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; startIndex, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; totalCount)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      totalCount = 0;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;switch&lt;/span&gt; (claimType)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;str&quot;&gt;&quot;http://schemas.microsoft.com/ws/2008/06/identity/claims/role&quot;&lt;/span&gt;:&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.SearchRoles(partOfValue, startIndex, maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; totalCount);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;str&quot;&gt;&quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name&quot;&lt;/span&gt;:&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;str&quot;&gt;&quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier&quot;&lt;/span&gt;:&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.SearchUsers(partOfValue, startIndex, maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; totalCount);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;str&quot;&gt;&quot;http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress&quot;&lt;/span&gt;:&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;.IsNullOrEmpty(partOfValue))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;              &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;.SearchEmails(partOfValue, startIndex, maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; totalCount);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;              &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Enumerable.Empty&amp;lt;SecurityEntity&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;default&lt;/span&gt;:&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Enumerable.Empty&amp;lt;SecurityEntity&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; IEnumerable&amp;lt;SecurityEntity&amp;gt; SearchEmails(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; partOfName, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; startIndex, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; totalCount)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; usersList = _db.Users.ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; users = usersList.Where(a =&amp;gt; a.Email != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt; &amp;amp;&amp;amp; a.Email.ToLower().Contains(partOfName.ToLower())).ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; entityList = users.Select(user =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SecurityEntity(user.Email)).ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        totalCount = entityList.Count;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; entityList;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; IEnumerable&amp;lt;SecurityEntity&amp;gt; SearchUsers(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; partOfName, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; startIndex, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; totalCount)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        totalCount = 0;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (_db.Users == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;) &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Enumerable.Empty&amp;lt;SecurityEntity&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; usersList = _db.Users.ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; entityList = !&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;.IsNullOrEmpty(partOfName) ? usersList.Where(a =&amp;gt; a.UserName.ToLower().Contains(partOfName.ToLower())).ToList().Select(user =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SecurityEntity(user.UserName)).ToList() : usersList.Select(user =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SecurityEntity(user.UserName)).ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        totalCount = entityList.Count;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; entityList;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; IEnumerable&amp;lt;SecurityEntity&amp;gt; SearchRoles(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; partOfName, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; startIndex, &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; maxRows, &lt;span class=&quot;kwrd&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt; totalCount)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        totalCount = 0;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (_db.Roles == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;) &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Enumerable.Empty&amp;lt;SecurityEntity&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; rolesList = _db.Roles.ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; roles = rolesList.Where(a =&amp;gt; a.Name.ToLower().Contains(partOfName.ToLower())).ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; entityList = roles.Select(role =&amp;gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; SecurityEntity(role.Name)).ToList();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        totalCount = entityList.Count;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; entityList;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;b&gt;TIPS!&lt;/b&gt; Do not forget to add your “CustomGroups” to the correct location paths in Web.Config, e.g. the admin part. Or else the users in this group will not be able to access the edit and admin in EPiServer. &lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;EPiServer/CMS/admin&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;authorization&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;allow&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;roles&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;WebAdmins, Administrators, &lt;span style=&quot;background-color: yellow;&quot;&gt;CustomGroup&lt;/span&gt;&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;deny&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;authorization&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;After you are finished with compiling, you should be able to create new custom roles in the Admin tool solution I have created earlier.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-5yuqkwWYTYs/Vjs0i7btppI/AAAAAAAAAmg/ELB-jGnw-qY/s1600/3-CreateRole.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;264&quot; src=&quot;http://3.bp.blogspot.com/-5yuqkwWYTYs/Vjs0i7btppI/AAAAAAAAAmg/ELB-jGnw-qY/s400/3-CreateRole.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Then you can click add “Users/ group button” in the “Set Access rights” module. Choose users or group and then add it with the green arrows and click OK.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-p9F1GjZ1Jc8/Vjs0jGet96I/AAAAAAAAAms/9wIgnLZX88U/s1600/3-RolesAddRole.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;400&quot; src=&quot;http://3.bp.blogspot.com/-p9F1GjZ1Jc8/Vjs0jGet96I/AAAAAAAAAms/9wIgnLZX88U/s400/3-RolesAddRole.JPG&quot; width=&quot;356&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Then it will appear in the list below. Problem solved!&lt;br /&gt;&lt;br /&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-ZuK5cdaRGHc/VjsynOS_YII/AAAAAAAAAmU/uC6lJ1YeEDE/s1600/3-RolesEdit.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;214&quot; src=&quot;http://3.bp.blogspot.com/-ZuK5cdaRGHc/VjsynOS_YII/AAAAAAAAAmU/uC6lJ1YeEDE/s400/3-RolesEdit.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Happy coding!</description>            <guid>http://sveinaandahl.blogspot.com/2015/11/how-to-fix-roles-in-episerver-when.html</guid>            <pubDate>Thu, 05 Nov 2015 12:20:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>Admin tool for ASP.NET Identity integrated with EPiServer CMS 8</title>            <link>http://sveinaandahl.blogspot.com/2015/08/admin-tool-for-aspnet-identity.html</link>            <description>&lt;h3&gt;Introduction&lt;/h3&gt;When you integrate ASP.NET Identity with EPiServer you will get a new database for the users, which will be created by the Entity Framework. First time you run the solution this database will be created and will be clean. We need an editor to be able to create and manage users and roles. Since I didn&#39;t find any editor that suited my need, I ended up building one myself. The result you can see in the picture below.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-17Ypn7IitHQ/VcxwQuFg7FI/AAAAAAAAAk8/EbZ-adwSDGA/s1600/EPiAdmin.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;283&quot; src=&quot;http://3.bp.blogspot.com/-17Ypn7IitHQ/VcxwQuFg7FI/AAAAAAAAAk8/EbZ-adwSDGA/s400/EPiAdmin.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;I have worked with EPiServer since early 2000&#39;s, but I can’t remember the Admin has changed much. Sure could need some love. I wish that all the links under “Access Rights” could disappear except “Set Access Rights”, when the ASP.NET membership was disabled and that you could add plugins to the “Access Rights” area. Nevertheless, for now we must add it to the “Tools” area.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;NB!&lt;/b&gt; Before you go on, you should take a look at “&lt;a href=&quot;http://sveinaandahl.blogspot.no/2015/08/how-to-integrate-aspnet-identity-with.html&quot; target=&quot;_blank&quot;&gt;How to integrate ASP.NET Identity with EPiServer 8&lt;/a&gt;”&lt;a href=&quot;https://www.blogger.com/&quot;&gt;&lt;/a&gt;, if you haven&#39;t read this first.&lt;br /&gt;&lt;br /&gt;&lt;h3 style=&quot;background-color: white; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; margin: 0px; position: relative;&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;Source Code&lt;/span&gt;&lt;/h3&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;background-color: white; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2px;&quot;&gt;Demo source code for this solution can be downloaded, which also includes the Admin tool:&lt;/span&gt;&lt;br style=&quot;background-color: white; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2px;&quot; /&gt;&lt;span lang=&quot;EN-US&quot; style=&quot;background-color: white; color: #444444; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18.2px;&quot;&gt;&lt;a href=&quot;https://github.com/saandahl/IdentityDemo&quot; style=&quot;color: #4d469c; text-decoration: none;&quot; target=&quot;_blank&quot;&gt;https://github.com/saandahl/IdentityDemo&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3&gt;Install necessary Nuget Packages&lt;/h3&gt;&lt;div&gt;First, we need to install some nuget packages. Open the Tools &amp;gt; Nuget Package Manager &amp;gt; Package Manager Console and run this commands:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package PagedList&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package PagedList.Mvc&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package Microsoft.jQuery.Unobtrusive.Ajax&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;The PagedList will add a new folder “Content” and the jQuery package will add a folder called “Scripts”. All need for the Admin tool.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h3&gt;Source code for the Admin Tool&lt;/h3&gt;&lt;div&gt;To avoid getting the reward for the longest blog post ever, I stored the source code for both ASP.NET Identity integration and the Admin Tool on Github. You can find that &lt;a href=&quot;https://github.com/saandahl/IdentityDemo&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Here is an overview what files that was added or changed to make this work in the Alloy Demo:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Content &amp;gt; Site.css&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;This CSS was created to fix some missing tags, but most the CSS is reused from EPiServer.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Models &amp;gt; Account &amp;gt; AccountViewModels.cs&lt;/b&gt;&lt;br /&gt;Includes models for both editor and login view.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Helpers &amp;gt; HtmlHelpers.cs&lt;/b&gt;&lt;/div&gt;&lt;div&gt;The ActivePage function was added to get the tabs correct in the editor.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Views &amp;gt; Identity&amp;nbsp;&lt;/b&gt;&lt;br /&gt;This folder include all the views for the editor.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Views &amp;gt; Shared &amp;gt; Layout &amp;gt; _LayoutIdentity.cshtml&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Master page for the editor. Some of the CSS could get wrong url if you use a different version of EPiServer. Could probably use some other CSS files. But, it works for the demo.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3&gt;Web.config&lt;/h3&gt;&lt;div&gt;&lt;b&gt;NB! &lt;/b&gt;Do not apply this code snippet before you have created an &lt;b&gt;admin user&lt;/b&gt; with both WebAdmins and WebEditors role.&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Identity&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;authorization&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;allow&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;roles&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;WebAdmins, Administrators&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;deny&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;users&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;authorization&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;h2&gt;How to create an user?&lt;/h2&gt;So when you can got all the files and code in place and build is succesfull. Open the startpage and then add &quot;/Identity/Index&quot; in the URL. If you got all the code correct you should be able to get something like this up in you browser:&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-AQ4qLfiJjJM/Vcx9qfha5ZI/AAAAAAAAAlQ/hbeI9nnZ-1c/s1600/AddRoles.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: left;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;270&quot; src=&quot;http://4.bp.blogspot.com/-AQ4qLfiJjJM/Vcx9qfha5ZI/AAAAAAAAAlQ/hbeI9nnZ-1c/s400/AddRoles.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Then click on the Create User tab and create a new account.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-7zqIfQ9Po-Y/Vcx9qRxD81I/AAAAAAAAAlk/-V5fQ_5TT14/s1600/CreateUser.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;271&quot; src=&quot;http://3.bp.blogspot.com/-7zqIfQ9Po-Y/Vcx9qRxD81I/AAAAAAAAAlk/-V5fQ_5TT14/s400/CreateUser.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Then go to the Manage Roles tab. Add both “WebAdmins” and “WebEditors”.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/--q9EmL0_t9E/Vcx9q95kEcI/AAAAAAAAAlo/AYxXVHZHqRM/s1600/ManageRoles.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;271&quot; src=&quot;http://2.bp.blogspot.com/--q9EmL0_t9E/Vcx9q95kEcI/AAAAAAAAAlo/AYxXVHZHqRM/s400/ManageRoles.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Then Click on the Account overview tab and hit “Roles for user” button. Here you can add the roles you just added.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-AQ4qLfiJjJM/Vcx9qfha5ZI/AAAAAAAAAlY/nf5V1CRGJaM/s1600/AddRoles.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;270&quot; src=&quot;http://2.bp.blogspot.com/-AQ4qLfiJjJM/Vcx9qfha5ZI/AAAAAAAAAlY/nf5V1CRGJaM/s400/AddRoles.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;Now you should be able to login at this URL /Account/Login.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;b&gt;NB!&lt;/b&gt; Don’t forget to add the web.config snippet after you have verify that your user have managed to login or else everyone can do the same as you just did.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2015/08/admin-tool-for-aspnet-identity.html</guid>            <pubDate>Fri, 14 Aug 2015 14:06:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to integrate ASP.NET Identity with EPiServer 8</title>            <link>http://sveinaandahl.blogspot.com/2015/08/how-to-integrate-aspnet-identity-with.html</link>            <description>&lt;div class=&quot;MsoNormal&quot;&gt;&lt;h3&gt;Introduction&lt;/h3&gt;The standard way of authenticate in EPiServer with the membership provider version has been used for more than a decade and has become very limited to how modern authenticate and authorization is done.&lt;br /&gt;&lt;br /&gt;I believe that several of us has customers that request new functionality that we cannot provide with the standard EPiServer membership provider. I often see and hear that they want to be able to login with Facebook or other Identity providers. They want to be able to login with cusomter number, phone number og email as the user name. &amp;nbsp;Could we customize the identity data model with more fields? Could we have a two-factor login process, including sms?&lt;br /&gt;&lt;br /&gt;And more..&lt;br /&gt;&lt;br /&gt;By using ASP.NET Identity, you will be able to solve these requests. To avoid getting a very large blog post I have divide it into several.&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;First will be how you integrate the ASP.NET Identity in a standard EPiServer Alloy Demo with a login screen.&lt;/li&gt;&lt;li&gt;Second, will contain how to create an Admin tool to create and manage users and roles.&lt;/li&gt;&lt;li&gt;Third, will be about how you optimize and migrate data from the membership to the Identity model. Yes, by optimize the data model you could improve the performance a lot. I&#39;ll also show how you can keep the old passwords after migration.&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;For those who is not familiar with ASP.NET Identity&amp;nbsp;&lt;/span&gt;this could be a good place to start &lt;a href=&quot;http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;In addition, ASP.NET Identity has its fall pits, which Brock has summery up &lt;a href=&quot;http://brockallen.com/2013/10/20/the-good-the-bad-and-the-ugly-of-asp-net-identity/&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;First, we need a demo project. For those of you are not familiar with how to setup an EPiServer CMS Alloy demo with MVC, here is a quick introduction.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;h3&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;b&gt;Source Code&lt;/b&gt;&lt;/span&gt;&lt;/h3&gt;&lt;span lang=&quot;EN-US&quot;&gt;Demo source code for this solution can be downloaded, which also includes the Admin tool:&lt;/span&gt;&lt;br /&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;a href=&quot;https://github.com/saandahl/IdentityDemo&quot; target=&quot;_blank&quot;&gt;https://github.com/saandahl/IdentityDemo&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;h3&gt;&lt;br /&gt;&lt;/h3&gt;&lt;h3&gt;Create an EPiServer site&lt;/h3&gt;&lt;div class=&quot;MsoNormal&quot;&gt;First, you will need to install the EPiServer extensions in Visual Studio. Which you can find&lt;a href=&quot;https://visualstudiogallery.msdn.microsoft.com/4ad95160-e72f-4355-b53e-0994d2958d3e&quot; target=&quot;_blank&quot;&gt; here.&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;This will give you the ability to create new EPiServer sites. Just open Visual Studio, go to File and select New and Project. Then select Templates, Visual C#, EPiServer, and EPiServer Web Site, and provide a name.&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-zIZDKAZ6iAg/Vcs8LdN_56I/AAAAAAAAAkU/-gu8I_cSoGs/s1600/CreateSite.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;276&quot; src=&quot;http://2.bp.blogspot.com/-zIZDKAZ6iAg/Vcs8LdN_56I/AAAAAAAAAkU/-gu8I_cSoGs/s400/CreateSite.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;Then select Alloy (MVC) for a site with sample content.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-aft4circgrQ/Vcs8LcR1zAI/AAAAAAAAAkg/C1M8FjCJLYk/s1600/ChooseMVC.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;241&quot; src=&quot;http://3.bp.blogspot.com/-aft4circgrQ/Vcs8LcR1zAI/AAAAAAAAAkg/C1M8FjCJLYk/s400/ChooseMVC.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Hit “OK” to finalize the creation of the project. Then press F5 to build and open the website in a browser. Then the site should come up and look like this:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/--6qPkRpJ_3s/Vcs8LcgvGmI/AAAAAAAAAkk/GlHeuokx2dk/s1600/Defaultsite.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;328&quot; src=&quot;http://3.bp.blogspot.com/--6qPkRpJ_3s/Vcs8LcgvGmI/AAAAAAAAAkk/GlHeuokx2dk/s400/Defaultsite.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;b&gt;NB!&lt;/b&gt; To avoid any pitfalls later on I suggest that you restore the database (.mdf files) from the App_Data folder to an SQL server. ASP.NET Identity will also need its own database, but this will be generated from Entity Framework when you start it up the first time, if you got the correct access rights.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;I also recommend setting up a site in IIS and add Network Service account to both SQL and IIS application pool identity.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;The only thing you would need to change is the connectionString in the web.config. You will find example on how it could look like further down.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;h3 style=&quot;clear: both;&quot;&gt;Install necessary Nuget Packages&lt;/h3&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;So far so good. Now we need to install some nuget packages. Open the Tools &amp;gt; Nuget Package Manager &amp;gt; Package Manager Console and run this commands:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package Microsoft.Owin.Security.Cookies&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package Microsoft.Owin.Host.SystemWeb&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package Microsoft.AspNet.Identity.EntityFramework&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package Microsoft.AspNet.Identity.Owin&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;PM&amp;gt; Install-Package Microsoft.AspNet.WebApi&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;This will download the packages and add the necessary references to the project and all the packages references will be added to the packages.config.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;The marked files/folders are the only places you will need to add or modify the code to get this up and running.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-3-9qnsHLmpY/VcxvQApE9CI/AAAAAAAAAk0/UcFxmuWpj9Q/s1600/Solutiontree.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;http://1.bp.blogspot.com/-3-9qnsHLmpY/VcxvQApE9CI/AAAAAAAAAk0/UcFxmuWpj9Q/s640/Solutiontree.JPG&quot; width=&quot;192&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;App_Start &amp;gt; IdentityConfig.cs&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;&lt;span lang=&quot;EN-US&quot;&gt;This is where you can tighten or loosen up the password strengths. To be able to use small test password I have set it very low.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span lang=&quot;EN-US&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity.EntityFramework;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity.Owin;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; TestSite.Models.Account;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationUserManager : UserManager&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationUserManager(ApplicationUserStore store)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(store)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; ApplicationUserManager Create(IdentityFactoryOptions&amp;lt;ApplicationUserManager&amp;gt; options, IOwinContext context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; manager = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationUserManager(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationUserStore(context.Get&amp;lt;ApplicationDbContext&amp;gt;()));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Configure validation logic for usernames&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.UserValidator = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; UserValidator&amp;lt;ApplicationUser&amp;gt;(manager)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                AllowOnlyAlphanumericUserNames = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;rem&quot;&gt;//RequireUniqueEmail = true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            };&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Configure validation logic for passwords&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.PasswordValidator = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PasswordValidator&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                RequiredLength = 6,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                RequireNonLetterOrDigit = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                RequireDigit = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                RequireLowercase = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                RequireUppercase = &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            };&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Configure user lockout defaults&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.UserLockoutEnabledByDefault = &lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.MaxFailedAccessAttemptsBeforeLockout = 5;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// You can write your own provider and plug it in here.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.RegisterTwoFactorProvider(&lt;span class=&quot;str&quot;&gt;&quot;Phone Code&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PhoneNumberTokenProvider&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                MessageFormat = &lt;span class=&quot;str&quot;&gt;&quot;Your security code is {0}&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            });&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            manager.RegisterTwoFactorProvider(&lt;span class=&quot;str&quot;&gt;&quot;Email Code&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; EmailTokenProvider&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                Subject = &lt;span class=&quot;str&quot;&gt;&quot;Security Code&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                BodyFormat = &lt;span class=&quot;str&quot;&gt;&quot;Your security code is {0}&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            });&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; dataProtectionProvider = options.DataProtectionProvider;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (dataProtectionProvider != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                manager.UserTokenProvider =&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DataProtectorTokenProvider&amp;lt;ApplicationUser&amp;gt;(dataProtectionProvider.Create(&lt;span class=&quot;str&quot;&gt;&quot;ASP.NET Identity&quot;&lt;/span&gt;));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; manager;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;// Configure the application sign-in manager which is used in this application.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationSignInManager : SignInManager&amp;lt;ApplicationUser, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationSignInManager(ApplicationUserManager userManager, IAuthenticationManager authenticationManager)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(userManager, authenticationManager)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; Task&amp;lt;ClaimsIdentity&amp;gt; CreateUserIdentityAsync(ApplicationUser user)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; user.GenerateUserIdentityAsync((ApplicationUserManager)UserManager);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; ApplicationSignInManager Create(IdentityFactoryOptions&amp;lt;ApplicationSignInManager&amp;gt; options,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            IOwinContext context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationSignInManager(context.GetUserManager&amp;lt;ApplicationUserManager&amp;gt;(), context.Authentication);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationUserStore : UserStore&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationUserStore(ApplicationDbContext ctx)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(ctx)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationRoleStore : RoleStore&amp;lt;IdentityRole&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationRoleStore(ApplicationDbContext ctx)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(ctx)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationRoleManager : RoleManager&amp;lt;IdentityRole&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationRoleManager(ApplicationRoleStore roleStore)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(roleStore)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;Controllers &amp;gt; AccountController.cs&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Mvc;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity.Owin;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; TestSite.Models.Account;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Controllers&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    [Authorize]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; AccountController : Controller&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; ApplicationSignInManager _signInManager;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; ApplicationUserManager _userManager;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; AccountController()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            UserManager = userManager;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            SignInManager = signInManager;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationSignInManager SignInManager&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; _signInManager ?? HttpContext.GetOwinContext().Get&amp;lt;ApplicationSignInManager&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                _signInManager = value;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationUserManager UserManager&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; _userManager ?? HttpContext.GetOwinContext().GetUserManager&amp;lt;ApplicationUserManager&amp;gt;();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                _userManager = value;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// GET: /Account/Login&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [AllowAnonymous]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult Login(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            ViewBag.ReturnUrl = returnUrl;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// POST: /Account/Login&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [HttpPost]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [AllowAnonymous]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [ValidateAntiForgeryToken]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; async Task&amp;lt;ActionResult&amp;gt; Login(LoginViewModel model, &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (ModelState.IsValid)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; user = await UserManager.FindAsync(model.UserName, model.Password);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (user != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    await SignInAsync(user, model.RememberMe);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; RedirectToLocal(returnUrl);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                ModelState.AddModelError(&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;Invalid username or password.&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// If we got this far, something failed, redisplay form&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; View(model);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;//&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// POST: /Account/LogOff&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [HttpPost]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [ValidateAntiForgeryToken]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ActionResult LogOff()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            Request.GetOwinContext().Authentication.SignOut();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Redirect(&lt;span class=&quot;str&quot;&gt;&quot;/&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Dispose(&lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; disposing)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (disposing &amp;amp;&amp;amp; UserManager != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                UserManager.Dispose();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                UserManager = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;.Dispose(disposing);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; Helpers&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; IAuthenticationManager AuthenticationManager&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt; { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; HttpContext.GetOwinContext().Authentication; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; async Task SignInAsync(ApplicationUser user, &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; isPersistent)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            AuthenticationManager.SignIn(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; AuthenticationProperties { IsPersistent = isPersistent }, identity);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; ActionResult RedirectToLocal(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; returnUrl)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (Url.IsLocalUrl(returnUrl))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Redirect(returnUrl);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Redirect(&lt;span class=&quot;str&quot;&gt;&quot;/&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;Models &amp;gt; Account &amp;gt; AccountViewModels.cs&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.ComponentModel.DataAnnotations;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Models.Account&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; LoginViewModel&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [Required]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [Display(Name = &lt;span class=&quot;str&quot;&gt;&quot;User name&quot;&lt;/span&gt;)]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; UserName { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [Required]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [DataType(DataType.Password)]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [Display(Name = &lt;span class=&quot;str&quot;&gt;&quot;Password&quot;&lt;/span&gt;)]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; Password { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        [Display(Name = &lt;span class=&quot;str&quot;&gt;&quot;Remember me?&quot;&lt;/span&gt;)]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; RememberMe { &lt;span class=&quot;kwrd&quot;&gt;get&lt;/span&gt;; &lt;span class=&quot;kwrd&quot;&gt;set&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;Models &amp;gt; Account &amp;gt; ApplicationUser.cs&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Data.Entity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity.EntityFramework;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite.Models.Account&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationUser : IdentityUser&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; async Task&amp;lt;ClaimsIdentity&amp;gt; GenerateUserIdentityAsync(UserManager&amp;lt;ApplicationUser&amp;gt; manager)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;var&lt;/span&gt; userIdentity = await manager.CreateIdentityAsync(&lt;span class=&quot;kwrd&quot;&gt;this&lt;/span&gt;, DefaultAuthenticationTypes.ApplicationCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Add custom user claims here&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; userIdentity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; ApplicationDbContext : IdentityDbContext&amp;lt;ApplicationUser&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; ApplicationDbContext()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            : &lt;span class=&quot;kwrd&quot;&gt;base&lt;/span&gt;(&lt;span class=&quot;str&quot;&gt;&quot;EcfSqlConnection&quot;&lt;/span&gt;, throwIfV1Schema: &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            Database.SetInitializer&amp;lt;ApplicationDbContext&amp;gt;(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; DropCreateDatabaseIfModelChanges&amp;lt;ApplicationDbContext&amp;gt;());&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; ApplicationDbContext Create()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; ApplicationDbContext();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;Views &amp;gt; Account &amp;gt; Login.cshtml&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Optimization&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@model TestSite.Models.Account.LoginViewModel&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    ViewBag.Title = &lt;span class=&quot;str&quot;&gt;&quot;Log in&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    Layout = &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;meta http-equiv=&lt;span class=&quot;str&quot;&gt;&quot;X-UA-Compatible&quot;&lt;/span&gt; content=&lt;span class=&quot;str&quot;&gt;&quot;IE=EmulateIE7&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; href=&lt;span class=&quot;str&quot;&gt;&quot;/util/styles/login.css&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;meta name=&lt;span class=&quot;str&quot;&gt;&quot;robots&quot;&lt;/span&gt; content=&lt;span class=&quot;str&quot;&gt;&quot;noindex,nofollow&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link href=&lt;span class=&quot;str&quot;&gt;&quot;../App_Themes/Default/Styles/system.css&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;link href=&lt;span class=&quot;str&quot;&gt;&quot;../App_Themes/Default/Styles/ToolButton.css&quot;&lt;/span&gt; type=&lt;span class=&quot;str&quot;&gt;&quot;text/css&quot;&lt;/span&gt; rel=&lt;span class=&quot;str&quot;&gt;&quot;stylesheet&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;body &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginBody&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginContainer&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginTop&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginMiddle&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginContent&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginLogo&quot;&lt;/span&gt;&amp;gt;@ViewBag.Title.&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginForm&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;h1&amp;gt;&amp;lt;span style=&lt;span class=&quot;str&quot;&gt;&quot;color: Red;&quot;&lt;/span&gt;&amp;gt;&amp;lt;/span&amp;gt;&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;div id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_ValidationSummary1&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-credentialsContainer&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            @&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; (Html.BeginForm(&lt;span class=&quot;str&quot;&gt;&quot;Login&quot;&lt;/span&gt;, &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;form-horizontal&quot;&lt;/span&gt;, role = &lt;span class=&quot;str&quot;&gt;&quot;form&quot;&lt;/span&gt; }))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                @Html.AntiForgeryToken()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                @Html.ValidationSummary(&lt;span class=&quot;kwrd&quot;&gt;true&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-float-left&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    @Html.LabelFor(m =&amp;gt; m.UserName, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;episize80&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.TextBoxFor(m =&amp;gt; m.UserName, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;epi-inputText&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.ValidationMessageFor(m =&amp;gt; m.UserName)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_RequiredFieldValidator1&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&#173;&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-float-left&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    @Html.LabelFor(m =&amp;gt; m.Password, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;episize80&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;br /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.PasswordFor(m =&amp;gt; m.Password, &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { @&lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; = &lt;span class=&quot;str&quot;&gt;&quot;epi-inputText&quot;&lt;/span&gt; })&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.ValidationMessageFor(m =&amp;gt; m.Password)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span id=&lt;span class=&quot;str&quot;&gt;&quot;FullRegion_LoginControl_RequiredFieldValidator2&quot;&lt;/span&gt; style=&lt;span class=&quot;str&quot;&gt;&quot;display: none;&quot;&lt;/span&gt;&amp;gt;&#173;&amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button-container epi-float-left&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        &amp;lt;span &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button-child&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                            &amp;lt;input type=&lt;span class=&quot;str&quot;&gt;&quot;submit&quot;&lt;/span&gt; value=&lt;span class=&quot;str&quot;&gt;&quot;Log in&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-button-child-item&quot;&lt;/span&gt; /&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        &amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-checkbox-container&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;span &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-checkbox&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.CheckBoxFor(m =&amp;gt; m.RememberMe)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                        @Html.LabelFor(m =&amp;gt; m.RememberMe)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                    &amp;lt;/span&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;div &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;str&quot;&gt;&quot;epi-loginBottom&quot;&lt;/span&gt;&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;lt;/body&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;@section Scripts {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    @Scripts.Render(&lt;span class=&quot;str&quot;&gt;&quot;~/bundles/jqueryval&quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;Startup.cs&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.Owin.Security.Cookies;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Owin;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Helpers;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; Microsoft.AspNet.Identity.Owin;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Security.Claims;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Threading.Tasks;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; TestSite.App_Start;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; TestSite.Models.Account;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;[assembly: OwinStartup(&lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(TestSite.Startup))]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; Startup&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; LogoutUrl = &lt;span class=&quot;str&quot;&gt;&quot;/util/logout.aspx&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Configuration(IAppBuilder app)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            ConfigureAuth(app);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; ConfigureAuth(IAppBuilder app)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Configure the db context, user manager and signin manager to use a single instance per request&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.CreatePerOwinContext(ApplicationDbContext.Create);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.CreatePerOwinContext&amp;lt;ApplicationUserManager&amp;gt;(ApplicationUserManager.Create);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.CreatePerOwinContext&amp;lt;ApplicationSignInManager&amp;gt;(ApplicationSignInManager.Create);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Enable the application to use a cookie to store information for the signed in user&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// and to use a cookie to temporarily store information about a user logging in with a third party login provider&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Configure the sign in cookie&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.UseCookieAuthentication(&lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CookieAuthenticationOptions&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                LoginPath = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PathString(&lt;span class=&quot;str&quot;&gt;&quot;/Account/Login&quot;&lt;/span&gt;),&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                Provider = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CookieAuthenticationProvider&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;rem&quot;&gt;// Enables the application to validate the security stamp when the user logs in.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;rem&quot;&gt;// This is a security feature which is used when you change a password or add an external login to your account.  &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    OnValidateIdentity =&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                        SecurityStampValidator.OnValidateIdentity&amp;lt;ApplicationUserManager, ApplicationUser&amp;gt;(&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            validateInterval: TimeSpan.FromMinutes(30),&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                            regenerateIdentity: (manager, user) =&amp;gt; user.GenerateUserIdentityAsync(manager))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                },&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                LogoutPath = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; PathString(&lt;span class=&quot;str&quot;&gt;&quot;/Account/LogOff&quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            });&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.Map(LogoutUrl, map =&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                map.Run(ctx =&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    ctx.Authentication.SignOut();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    ctx.Response.Redirect(&lt;span class=&quot;str&quot;&gt;&quot;/&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                    &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; Task.FromResult(0);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                });&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            });&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//Tell antiforgery to use the name claim&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Name;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Enables the application to temporarily store user information when &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// they are verifying the second factor in the two-factor authentication process.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.UseTwoFactorSignInCookie(&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                DefaultAuthenticationTypes.TwoFactorCookie,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                TimeSpan.FromMinutes(5));&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Enables the application to remember the second login verification factor such &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// as phone or email. Once you check this option, your second step of &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// verification during the login process will be remembered on the device where &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// you logged in from. This is similar to the RememberMe option when you log in.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            app.UseTwoFactorRememberBrowserCookie(&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Uncomment the following lines to enable logging in &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// with third party login providers&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//app.UseMicrosoftAccountAuthentication(&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//    clientId: &quot;&quot;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//    clientSecret: &quot;&quot;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//app.UseTwitterAuthentication(&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//   consumerKey: &quot;&quot;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//   consumerSecret: &quot;&quot;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//app.UseFacebookAuthentication(&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//   appId: &quot;&quot;,&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//   appSecret: &quot;&quot;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;//app.UseGoogleAuthentication();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;InitializationRouting.cs&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;Instead of handle the routing in the Global.asax you can add this as a InitialeizableModule. Have added the routing for the admin tool in this part too.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt; &lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Http;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Mvc;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Web.Routing;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Framework;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; EPiServer.Framework.Initialization;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; TestSite&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    [InitializableModule]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    [ModuleDependency(&lt;span class=&quot;kwrd&quot;&gt;typeof&lt;/span&gt;(EPiServer.Web.InitializationModule))]&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; InitializationRouting : IInitializableModule&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Register(HttpConfiguration config)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            &lt;span class=&quot;rem&quot;&gt;// Attribute routing.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            config.MapHttpAttributeRoutes();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            RouteTable.Routes.MapRoute(&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                name: &lt;span class=&quot;str&quot;&gt;&quot;IdentityEditor&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                url: &lt;span class=&quot;str&quot;&gt;&quot;Identity/{action}/{id}&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                defaults: &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { controller = &lt;span class=&quot;str&quot;&gt;&quot;Identity&quot;&lt;/span&gt;, action = &lt;span class=&quot;str&quot;&gt;&quot;index&quot;&lt;/span&gt;, id = UrlParameter.Optional }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            );&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            RouteTable.Routes.MapRoute(&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                name: &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                url: &lt;span class=&quot;str&quot;&gt;&quot;Account/{action}/{id}&quot;&lt;/span&gt;,&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;                defaults: &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; { controller = &lt;span class=&quot;str&quot;&gt;&quot;Account&quot;&lt;/span&gt;, action = &lt;span class=&quot;str&quot;&gt;&quot;login&quot;&lt;/span&gt;, id = UrlParameter.Optional }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            );&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Initialize(InitializationEngine context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;            GlobalConfiguration.Configure(Register);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Preload(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;[] parameters) { }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Uninitialize(InitializationEngine context) { }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;h4&gt;&lt;span lang=&quot;EN-US&quot;&gt;Web.config&lt;/span&gt;&lt;/h4&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;&amp;lt;!--Change :&amp;nbsp;&lt;/span&gt;You don&#39;t have to change the login code in the Alloy demo as long as you add the new loginurl.--&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;authentication&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;None&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;forms&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;loginUrl&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;~/Account/Login&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;2880&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;authentication&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;&amp;lt;!--Change--&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;membership&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;false&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;clear&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;membership&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;roleManager&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;enabled&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;false&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;clear&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;roleManager&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.webServer&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;rem&quot;&gt;&amp;lt;!--Change--&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;connectionStrings&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;EPiServerDB&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;connectionString&lt;/span&gt;=&quot;&lt;span class=&quot;attr&quot;&gt;Data&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;Source&lt;/span&gt;=&amp;lt;&lt;span class=&quot;attr&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;;Initial Catalog=EPiServerDB_4380c2ee;Integrated Security=False;User ID=dbUser;Password=*****;MultipleActiveResultSets=True&quot; providerName=&quot;System.Data.SqlClient&quot; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;EcfSqlConnection&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;connectionString&lt;/span&gt;=&quot;&lt;span class=&quot;attr&quot;&gt;Data&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;Source&lt;/span&gt;=&amp;lt;&lt;span class=&quot;attr&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;;Initial Catalog=TestSiteIdentityDB;Integrated Security=True&quot; providerName=&quot;System.Data.SqlClient&quot; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;connectionStrings&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;Now you could either add ~/Account/Login in the url or click on the login button in the Alloy Demo. Then something like this should pop up.  &lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-YE0ve4GyZ7k/Vcs8MOk6l7I/AAAAAAAAAkY/15zaEAH45zc/s1600/Login.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;298&quot; src=&quot;http://2.bp.blogspot.com/-YE0ve4GyZ7k/Vcs8MOk6l7I/AAAAAAAAAkY/15zaEAH45zc/s400/Login.JPG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;This solution could now easily be extended with &quot;my page&quot; functionality where the user could manage his own information. I haven&#39;t added this to keep the example as small as possible.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;How to login?&lt;/h2&gt;The major problem now is that you don’t have any account to login with. Check out the Admin tool i have built to create and maintain users and roles for ASP.NET Identity. Read more about that &lt;a href=&quot;http://sveinaandahl.blogspot.no/2015/08/admin-tool-for-aspnet-identity.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2015/08/how-to-integrate-aspnet-identity-with.html</guid>            <pubDate>Fri, 14 Aug 2015 14:06:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to connect a PIM system to EPiServer Commerce 7.5 - part 2</title>            <link>http://sveinaandahl.blogspot.com/2014/04/how-to-connect-pim-system-to-episerver.html</link>            <description>In the first part I went through how to setup the inRiver Server and how to connect the Rich Client editor up against it. In this last part, I will describe how you setup the connection between the PIM solution, inRiver Server 5.3, and EPiServer Commerce 7.5. So here is a introduction&amp;nbsp;to&amp;nbsp;a inRiver solution&amp;nbsp;with&amp;nbsp;publishing products into your EPiServer commerce catalog.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;div&gt;Architecture&lt;/div&gt;&lt;/h3&gt;There are several ways to create products and items in the PIM solution. You could of course create products manually or by import of an excel sheet.&amp;nbsp; But normally you would create these products through integration&amp;nbsp;from an ERP system. You could either use inbound connection in inRiver or use a mapping through an integration platform, like BizTalk, from an ERP system to PIM’s service/API.&lt;br /&gt;&lt;br /&gt;After the creation of the products, you could enrich them with more and better pictures and extend the content. Then create different channels you want to publish the products too. In this particular solution we want to publish it to the EPiServer commerce platform.&lt;br /&gt;&lt;br /&gt;With inRiver Connect you will be able to export products and resources to EPiServer Commerce’s catalog. You will do that with an existing EPiServer Adapter. There are adapters for other CMS and software too.&lt;br /&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-39-m_pbs2QI/U0TuCrz4mBI/AAAAAAAAAec/kNUJgSOKV5M/s1600/Architecture2.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-39-m_pbs2QI/U0TuCrz4mBI/AAAAAAAAAec/kNUJgSOKV5M/s1600/Architecture2.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;This blog post requires that you already have installed inRiver Server 5.3 and EPiServer Commerce 7.5. If you haven’t installed Commerce or inRiver server yet, you can find an installation guide for both&amp;nbsp;here:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;inRiver:&lt;/strong&gt; &lt;a href=&quot;http://sveinaandahl.blogspot.no/2014/04/how-to-connect-pim-solution-to.html&quot;&gt;http://sveinaandahl.blogspot.no/2014/04/how-to-connect-pim-solution-to.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Commerce:&lt;/strong&gt; &lt;a href=&quot;/link/a05a52c71f9e4474b3c6218ab3262d3e.aspx&quot;&gt;http://world.episerver.com/Documentation/Items/Installation-Instructions/EPiServer-Commerce/Installation-instructions-EPiServer-75-Commerce/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Before we start with installing inRiver Connect, there are a few administration tools you need to&amp;nbsp;install on the inRiver server. &lt;br /&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;If you haven’t done it already I recommend you to install Internet Information Services (IIS) on the inRiver server, since you will need this for inRiver Administration, inRiver WebClient and inRiver Web Media Browser. Also install Microsoft .NET Framework 4.0 or 4.5 if running Windows 2012 Server.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;div&gt;Install Administration Web&lt;/div&gt;&lt;/h3&gt;The installation procedure is straight forward. Run installation file “Setup inRiver Rich Client.exe”.&amp;nbsp; Proceed forward by clicking &quot;Next&quot; until the installation is finished. &lt;br /&gt;&lt;br /&gt;&lt;div&gt;You can go to this URL &lt;a href=&quot;http://localhost/Server/Default.aspx&quot;&gt;http://localhost:80/Server/Default.aspx&lt;/a&gt; after you finished the installation. You can change the localhost with a DNS name or machine name, if you configurate it in IIS.&lt;/div&gt;&lt;div&gt;This is how it will look after you got it up:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-t3bpUyMBbj4/U0VNyqQAOmI/AAAAAAAAAgM/Pa9SeBoCAc4/s1600/inriverstart.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-t3bpUyMBbj4/U0VNyqQAOmI/AAAAAAAAAgM/Pa9SeBoCAc4/s1600/inriverstart.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;The most important with the administration web for this scenario is the inRiver Connect tab, but we will come back to that.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;div&gt;Install Model tools&lt;/div&gt;&lt;/h3&gt;Model tools will be the most important configuration tool when you are going to shape the Meta data model of the PIM. You will also be able to define and create CVL (special drop down menus), types, field set, categories, and languages. &lt;br /&gt;&lt;br /&gt;Another reason why you need to install this editor now, is because you need the model tool to get the adapter to work by turning on the integration.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;The installation procedure is easy. Run installation file “Setup inRiver&amp;nbsp;Model tools.exe”.&amp;nbsp; Proceed forward by clicking &quot;Next&quot; until the installation is finished.&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-Du2H-1EFjJc/U0UuZSFhqGI/AAAAAAAAAgA/t7YRc_J7J7c/s1600/ModelToolInt.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-Du2H-1EFjJc/U0UuZSFhqGI/AAAAAAAAAgA/t7YRc_J7J7c/s1600/ModelToolInt.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&amp;nbsp;&lt;/div&gt;After started up Model tools click on the tab “Server settings”. Here you will find INTEGRATION_ENABLED property. Set it to “true” to enable integration to inRiver Connect.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Setup inRiver Connect&lt;/h3&gt;Okey, then we are ready to install the inRiver Connect.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;The installation procedure is straight forward. Run installation file “Setup inRiver Connect.exe”.&amp;nbsp; Proceed forward by clicking &quot;Next&quot; until the installation is finished.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;&lt;strong&gt;Services&lt;/strong&gt;&lt;/div&gt;Before you start the service make sure you have added an AD user to the service. Use the same AD user as you used for inRiver server.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-M_163di6NPw/U0JF8PIAQ0I/AAAAAAAAAcM/1zzw2PJgLWQ/s1600/serviceLogon.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-M_163di6NPw/U0JF8PIAQ0I/AAAAAAAAAcM/1zzw2PJgLWQ/s1600/serviceLogon.png&quot; width=&quot;348&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;After you have installed and finished the configuration, then you can start the service.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-zwJ6HEVuT6o/U0T2_DYqupI/AAAAAAAAAe8/Ali7bHRpMK8/s1600/serviceInriverConnect.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-zwJ6HEVuT6o/U0T2_DYqupI/AAAAAAAAAe8/Ali7bHRpMK8/s1600/serviceInriverConnect.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;Check the trouble shooting for MSMQ in the first blog post, if you got problem with starting the service. (&lt;a href=&quot;http://sveinaandahl.blogspot.no/2014/04/how-to-connect-pim-solution-to.html&quot;&gt;http://sveinaandahl.blogspot.no/2014/04/how-to-connect-pim-solution-to.html&lt;/a&gt;)&lt;/div&gt;After you already have installed the Administration web you can navigate to the inRiver Connect or type following URL in the browser: &lt;a href=&quot;http://localhost/Integration/Default.aspx&quot;&gt;http://localhost:80/Integration/Default.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Install EPiServer Commerce Adapter&lt;/h3&gt;There are also some system dll file that are part of the web API installation. You need version 4.0.30506 or newer. You can download it from here: &lt;a href=&quot;http://www.asp.net/mvc/mvc4&quot;&gt;http://www.asp.net/mvc/mvc4&lt;/a&gt;&amp;nbsp;or you can add the Microsoft.AspNet.WebApi Nuget Package.&lt;br /&gt;&lt;br /&gt;&lt;h4&gt;&lt;/h4&gt;&lt;strong&gt;Installing on inRiver side&lt;/strong&gt;&lt;br /&gt;Place the following files in the .\Program Files\inRiver AB\inRiver Connect\ OutboundConnectors\ folder :&lt;br /&gt;&lt;ul&gt;&lt;li&gt;inRiver.EPiServerCommerce.CommerceAdapter.dll&lt;/li&gt;&lt;li&gt;inRiver.EPiServerCommerce.MediaPublisher.dll&lt;/li&gt;&lt;li&gt;inRiver.EPiServerCommerce.Interfaces.dll&lt;/li&gt;&lt;li&gt;System.Net.Http.Formatting.dll &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(From the WEB API installation)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;strong&gt;Installation on EPiServer side&lt;/strong&gt;&lt;br /&gt;&lt;div&gt;In the bin folder in your EPiServer site you should copy the following files:&amp;nbsp;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&amp;nbsp;System.Web.Http.dll &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(From the WEB API installation)&lt;/li&gt;&lt;li&gt;&amp;nbsp;System.Web.Http.WebHost.dll&amp;nbsp;&amp;nbsp;&amp;nbsp;(From the WEB API installation)&lt;/li&gt;&lt;li&gt;&amp;nbsp;System.Net.Http.Formatting.dll&amp;nbsp;&amp;nbsp;&amp;nbsp;(From the WEB API installation)&lt;/li&gt;&lt;li&gt;&amp;nbsp;inRiver.EPiServerCommerce.Import.dll&lt;/li&gt;&lt;li&gt;&amp;nbsp;inRiver.EPiServerCommerce.Interfaces.dll&lt;/li&gt;&lt;/ul&gt;&lt;div&gt;Add the following app-settings in web.config in your episerver cms site:&lt;/div&gt;&lt;div&gt;&amp;nbsp;&lt;/div&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;-ms-word-wrap: normal; color: black;&quot;&gt; .....  &lt;br /&gt; &amp;lt;appSettings&amp;gt;  &lt;br /&gt;  ....  &lt;br /&gt;  &amp;lt;add key=&quot;inRiver.apikey&quot; value=&quot;yourApiKey&quot; /&amp;gt;   &lt;br /&gt;  &amp;lt;add key=&quot;inRiver.RunICatalogImportHandlers&quot; value=&quot;true&quot; /&amp;gt;   &lt;br /&gt; &amp;lt;/appSettings&amp;gt;  &lt;br /&gt; ...  &lt;/code&gt;&lt;code style=&quot;-ms-word-wrap: normal; color: black;&quot;&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;em&gt;inRiver.apikey&lt;/em&gt; is used to securing the communication, and the same apikey should be placed in the connector settings (look at EPI_APIKEY in the configuration picture below).&lt;br /&gt;&lt;br /&gt;&lt;em&gt;inRiver.RunICatalogImportHandlers&lt;/em&gt; should be set to true as default, but you have the option to disable your Handlers in runtime by&amp;nbsp;changing this setting to false.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;inRiver Adapter settings&lt;/strong&gt;&lt;br /&gt;Now go back to the web Adminstrator’s connect.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-biiEA_jv5ck/U0VOj32PpuI/AAAAAAAAAgU/12WgEoQNXlo/s1600/inRiverConnect.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-biiEA_jv5ck/U0VOj32PpuI/AAAAAAAAAgU/12WgEoQNXlo/s1600/inRiverConnect.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Here you can add a new Connector and a pop up window will give you a set of variables you will need to configure to create the connection to EPiServer Commerce.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-YdIaizi1-Ms/U1YhziLQHLI/AAAAAAAAAg8/k8YLMJaGKVM/s1600/ConncetConfig.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-YdIaizi1-Ms/U1YhziLQHLI/AAAAAAAAAg8/k8YLMJaGKVM/s1600/ConncetConfig.png&quot; width=&quot;460&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Here is a set of important configuration settings to get this connection to work. But you can find more information about each element in the inRiver wiki.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;PUBLISH_FOLDER &amp;amp; PUBLISH_FOLDER_RESOURCES&lt;/strong&gt; - These two configurations field will set the path to where you want to publish the content from inRiver.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;NOTE!&lt;/strong&gt; Both inRiver Connect and EPiServer Commerce user accounts should have access rights to these folders, so add both the AD user you used for the Connect service and “IIS_IUSRS”&amp;nbsp; that’s used in the commerce site.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;CHANNEL_ID &lt;/strong&gt;- You will find this ID in inRiver Rich Client editor. Open the Channel you want to publish and click Details. Click on the Information icon in the right top view. A pop up view will arrive where you can see the System ID which you can use as the Channel ID. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;NOTE!&lt;/strong&gt; If you are still confused, check out the picture from the from inRiver Rich Client below. The Information icon is in the small red circle.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EPI_CONNECTIONSTRING&lt;/strong&gt; – You’ll find this name in connectionstring.config in the EPiServer Commerce project.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EPI_APPLICATIONNAME &lt;/strong&gt;– Is the same name that you installed the Commerce site with in IIS. Default, that’s usually “EPiServerCommerceManager”.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EPI_ENDPOINT_URL&lt;/strong&gt; – This is the URL to the EPiServer site you installed. Rest of the URL is based on Restapi. So it should look something like this:&amp;nbsp; &lt;a href=&quot;http://%3cepiserver/&quot;&gt;http://&amp;lt;EPiServer commerce site&amp;gt;:80/inriverapi/InriverDataImport&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EPI_APIKEY&lt;/strong&gt; - It’s the same Key that was added to the web.config in the EPiServer site.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;EPI_RESTTIMEOUT&lt;/strong&gt; - The timeout in &lt;em&gt;hours&lt;/em&gt; for the calls to epi-server REST-API. Default set it to 1. If it doesn&#39;t exists you should create it by click on the &quot;Add setting&quot;.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Testing of publishing products from the PIM to the Commerce&lt;/h3&gt;I would recommend to begin with setting up log files for both side&amp;nbsp;to be able to trap errors.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Log files&lt;/strong&gt;&lt;br /&gt;If any error occurred in the Connector you would be able to look closer into it in this file: &lt;br /&gt;&lt;em&gt;C:\Program Files\inRiver AB\inRiver Connect\Log\inRiver.Connect.txt&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;For the import to EPiServer Commerce add the following code to EPiServerLog.config:&lt;br /&gt;&lt;br /&gt;&lt;pre style=&quot;background: rgb(240, 240, 240); border: 1px dashed rgb(204, 204, 204); color: black; font-family: arial; font-size: 12px; height: auto; line-height: 20px; overflow: auto; padding: 0px; text-align: left; width: 99%;&quot;&gt;&lt;code style=&quot;-ms-word-wrap: normal; color: black;&quot;&gt;   &amp;lt;appender name=&quot;inRiverCommerceImportLogger&quot;  &lt;br /&gt;        type=&quot;log4net.Appender.FileAppender&quot; &amp;gt;  &lt;br /&gt;     &amp;lt;file value=&quot;App_Data\inRiverCommerceImportLogger.log&quot; /&amp;gt;  &lt;br /&gt;     &amp;lt;encoding value=&quot;utf-8&quot; /&amp;gt;  &lt;br /&gt;     &amp;lt;lockingModel type=&quot;log4net.Appender.FileAppender+MinimalLock&quot; /&amp;gt;  &lt;br /&gt;     &amp;lt;layout type=&quot;log4net.Layout.PatternLayout&quot;&amp;gt;  &lt;br /&gt;       &amp;lt;conversionPattern value=&quot;%date [%thread] %level %logger: %message%n&quot; /&amp;gt;  &lt;br /&gt;     &amp;lt;/layout&amp;gt;  &lt;br /&gt;   &amp;lt;/appender&amp;gt;    &lt;br /&gt;   &amp;lt;logger name=&quot;inRiver&quot; additivity=&quot;false&quot;&amp;gt;  &lt;br /&gt;     &amp;lt;level value=&quot;Debug&quot; /&amp;gt;  &lt;br /&gt;     &amp;lt;appender-ref ref=&quot;inRiverCommerceImportLogger&quot; /&amp;gt;  &lt;br /&gt;   &amp;lt;/logger&amp;gt;  &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then you can watch information about the import of products to commerce in this file:&lt;br /&gt;&lt;em&gt;\EPiServerCommerce\wwwroot\App_Data\ inRiverCommerceImportLogger.txt&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;NOTE!&lt;/strong&gt; All the metadata that exists in inRiver, but are missing in Commerce will be created by the adapter. But keep in mind that fields that exists both places with different types will assert an error. So the best result will be to have an empty Commerce database. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Setting up and publish a Channel in inRiver Rich Client&lt;/strong&gt;&lt;br /&gt;There are a few pitfalls which you could run into here.&amp;nbsp; From experience I would recommend to pay close attention to what type of languages, types and field set that are defined. These are things that can come back and haunt you later in the log files. All these elements are editable in the model tools editor. I won’t go into details on how you do that here.&amp;nbsp;It would require another blog post.&lt;br /&gt;&lt;br /&gt;First you have to defined the different types you need to create a channel tree including nodes and products, as the big red circle are marking in the picture below. When that’s in place you can publish the channel. If the adapter is setup correct,&amp;nbsp;it would send the whole catalog and resources to EPiServer Commerce catalog. When a Channel is set to publish, all additions and updates will automatically be sent to EPiServer Commerce.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/--wdjzYxMn1c/U0UtxLFUbtI/AAAAAAAAAf8/bObBq8Rkid0/s1600/InRiverChannel2.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/--wdjzYxMn1c/U0UtxLFUbtI/AAAAAAAAAf8/bObBq8Rkid0/s1600/InRiverChannel2.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;strong&gt;Retrieving published products in EPiServer Commerce&lt;/strong&gt;&lt;br /&gt;So when you log on to the EPiServer Commerce and go to the catalog you will see the all the updates that comes from inRiver. Really sweet! &lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://4.bp.blogspot.com/-2WuFZ1kBMa8/U0UtxG5UQuI/AAAAAAAAAf4/L0eAeYMlGhs/s1600/CommerceCatalog2.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://4.bp.blogspot.com/-2WuFZ1kBMa8/U0UtxG5UQuI/AAAAAAAAAf4/L0eAeYMlGhs/s1600/CommerceCatalog2.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;If things don&#39;t show up as you expect, you should check out the log files.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;strong&gt;Last comment&lt;/strong&gt;&lt;br /&gt;Using a PIM will change the way the editors work.&amp;nbsp; The editors&amp;nbsp;will&amp;nbsp;work in the rich client editor to create and publish for example products, campaign&#39;s, PDF&#39;s and so on, in stand of working with&amp;nbsp;the commerce catalog in EPiServer.&lt;br /&gt;&lt;em&gt;&lt;/em&gt;&lt;br /&gt;That&#39;s it.&lt;br /&gt;&lt;br /&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2014/04/how-to-connect-pim-system-to-episerver.html</guid>            <pubDate>Tue, 22 Apr 2014 11:10:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to connect a PIM solution to EPiServer Commerce 7.5</title>            <link>http://sveinaandahl.blogspot.com/2014/04/how-to-connect-pim-solution-to.html</link>            <description>&lt;br /&gt;&lt;div&gt;Product Information Management, in short called PIM, is important for driving consistency product information across digital channels. A PIM solution will make all product information available from a central point in a reliable, meaningful, and timely way to people, processes and applications that rely on it. &lt;br /&gt;&lt;br /&gt;There have been written several blog post and information about PIM, but there are very few, if any, with in depth information on how you setup a PIM solution with EPiServer Commerce 7.5. The PIM solution I have used is inRiver 5.3, which have a really nice “out of the box” adapter to EPiServer Commerce.&lt;br /&gt;&lt;br /&gt;You can find a nice introduction to PIM here: &lt;span style=&quot;font-family: &amp;quot;Times New Roman&amp;quot;,&amp;quot;serif&amp;quot;; font-size: 12pt; mso-ansi-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;; mso-fareast-language: EN-US;&quot;&gt;&lt;a href=&quot;http://nordicecommerceknowledge.se/PIM--en-viktig-del-i-en-multikanalstrategi/&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;http://nordicecommerceknowledge.se/PIM--en-viktig-del-i-en-multikanalstrategi/&lt;/span&gt;&lt;/a&gt;&amp;nbsp;(only in Swedish)&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;The blog post became quite long, so I have split it up in two. First blog post will contain how to setup InRiver and how to connect the Rich Client Editor&amp;nbsp;to&amp;nbsp;it. I have tried to document some of the pitfalls you may run into.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div&gt;The second blog post will be about inRiver Connect and how you should configure it to be able to publish products to EPiServer Commerce.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;h3&gt;Architecture&lt;/h3&gt;&lt;div&gt;My solution is based on the same infrastructure setup as you see in the figure below. You could of course set it up on one single server, but it’s not recommended in a production environment. It is important to notice that inRiver can’t be setup with several servers in a load balancing environment. This is normally not a problem, but it’s advisable to&amp;nbsp;stack the inRiver server&amp;nbsp;with enough CPU power and memory to handle scaling and cropping of pictures, if you have a lot of channels to support.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-WtG99vTbibc/U0Jm4N5rhYI/AAAAAAAAAdw/tY6jwXH9VhU/s1600/inRiverInfrastruktur.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-WtG99vTbibc/U0Jm4N5rhYI/AAAAAAAAAdw/tY6jwXH9VhU/s1600/inRiverInfrastruktur.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Let&#39;s continue with the details on how to setup the SQL, inRiver server and Rich Client editor.&lt;br /&gt;&lt;br /&gt;&lt;h3 class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Necessary requirements when installing of Microsoft SQL &lt;/h3&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Let’s start with database first. You can install either Microsoft SQL 2012 R2 Server or SQL 2008 R2 Server. Remember to enable Filestream when you install it, since inRiver require it. Both inRiver and EPiServer Commerce requires you to use a full version of SQL, so using Web Edition of SQL Server is not suitable for any part of this solution.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;If you already got an MS SQL database available, then here is how you enable Filestream. Go to “Sql Server Configuration Manager” and open properties for the SQL server and enable Filestream.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-kqu-PKJZZ1w/U0Pc8lelqlI/AAAAAAAAAeM/7e9O4xG9eRg/s1600/filestream.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-kqu-PKJZZ1w/U0Pc8lelqlI/AAAAAAAAAeM/7e9O4xG9eRg/s1600/filestream.png&quot; height=&quot;400&quot; width=&quot;343&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;When you have clicked “OK” and then open “SQL Server Management Studio”. Copy following script and execute it:&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt; &lt;span style=&quot;color: maroon;&quot;&gt;sp_configure&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;color: teal;&quot;&gt;filestream_access_level&lt;/span&gt;&lt;span style=&quot;color: grey;&quot;&gt;,&lt;/span&gt; 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;RECONFIGURE&lt;/span&gt;&lt;span style=&quot;font-family: Consolas; font-size: 9.5pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style=&quot;line-height: normal; margin: 0cm 0cm 0pt; mso-layout-grid-align: none;&quot;&gt;&lt;span style=&quot;color: blue; font-family: Consolas; font-size: 9.5pt;&quot;&gt;Go&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;Now you can stop and start the SQL Server.&lt;br /&gt;&lt;br /&gt;You should now be able to perform a full restore of the database file inriver.bak that follows the install package for inRiver Server.&lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;&lt;strong&gt;TIPS!&lt;/strong&gt; &lt;a href=&quot;http://www.mssqltips.com/sqlservertip/1838/different-ways-to-enable-filestream-feature-of-sql-server-2008/&quot;&gt;http://www.mssqltips.com/sqlservertip/1838/different-ways-to-enable-filestream-feature-of-sql-server-2008/&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;h3&gt;&lt;div&gt;Couple of notes before continuing &lt;br /&gt;&amp;nbsp;&lt;/div&gt;&lt;/h3&gt;&lt;strong&gt;Note! SQL Server 2012&lt;/strong&gt;&lt;br /&gt;If you are running SQL Server 2012 integrated security it will not work &quot;out of the box&quot; like it does in SQL Server 2008, if you are running inRiver Server and SQL server on the same machine. You will then need to assign a specific user. &lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note! User Account ID&lt;/strong&gt;&lt;br /&gt;In this solution it’s recommended to use an Active Directory User, since several servers are involved. If it’s on the same server you can use an administrator user.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Note! IIS on the inRiver server&lt;/strong&gt;&lt;br /&gt;Recommend to install Internet Information Services (IIS) on the inRiver server, since you will need this for inRiver Administration, inRiver WebClient and inRiver Web Media Browser. Also install Microsoft .NET Framework 4.0 or 4.5 if running Windows 2012 Server.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;&lt;div&gt;Installation of inRiver Server&lt;/div&gt;&lt;/h3&gt;Finally ready for installing the inRiver Server.&lt;br /&gt;&lt;br /&gt;The installation procedure is very straight forward. Run installation file “Setup inRiver Server 5.3.exe”.&amp;nbsp; Proceed forward by clicking &quot;Next&quot; until the installation is finished. This will install the program as a service. &lt;br /&gt;&lt;br /&gt;After installation, open Windows Explorer and point it to the root directory of your inRiver Server installation and rename inRiver.Server.exe.config.sample to inRiver.Server.exe.config&lt;br /&gt;&lt;br /&gt;When you open the file in an editor, modify the text that’s inside the red square with either one of the two lines below the picture depending&amp;nbsp;of which sql you use.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-5NsmP4XAgHs/U0JlZo1RLnI/AAAAAAAAAdk/wbWG4WezQWk/s1600/inRiverConnect2.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-5NsmP4XAgHs/U0JlZo1RLnI/AAAAAAAAAdk/wbWG4WezQWk/s1600/inRiverConnect2.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;strong&gt;Connection string for sql 2008&lt;/strong&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;add name=&quot;inriver&quot; connectionString=&quot;Data Source=localhost\INRIVERSERVER;Initial Catalog=inriver_demo;Integrated Security=True;&quot; providerName=&quot;System.Data.SqlClient&quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;add name=&quot;inriverResources&quot; connectionString=&quot;Data Source=localhost\INRIVERSERVER;Initial Catalog=inriver_demo;Integrated Security=True;&quot; providerName=&quot;System.Data.SqlClient&quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;strong&gt;Connection string for sql 2012&lt;/strong&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Create a sql user that has DBO rights in the database first.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&amp;lt;add name=&quot;inriver&quot; connectionString=&quot;Data Source= localhost\SQLSERVER2012;Initial Catalog=inriver;Integrated Security=SSPI;User ID=dbUserInriver;Password=xxxxxx&quot; providerName=&quot;System.Data.SqlClient&quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;add name=&quot;inriverResources&quot; connectionString=&quot;Data Source= localhost\SQLSERVER2012;Initial Catalog=inriver;Integrated Security=SSPI;User ID=dbUserInriver;Password= xxxxxx;&quot; providerName=&quot;System.Data.SqlClient&quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Note that in large installations you can point &quot;inriver&quot; and &quot;inriverResources&quot; into two different instances.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;MSMQ&lt;/h3&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;The first pitfall coming up, MSMQ.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;em&gt;Make sure changes to the service Log On properties are made prior to the first start attempt of the service.&lt;/em&gt; &lt;em&gt;Else MSMQ queue objects might be created with inappropriate credentials.&lt;/em&gt; Check trouble shooting below, if you run into trouble.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;Installing MSMQ is easy enough. Go to Server Manager and add click on “Add a feature”, then add and install “Message Queuing Services”.&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;After installation you can open Computer Management. Under &quot;Services and Applications&quot; you will now have a &quot;Message Queuing&quot;. All queues later on will be created under &quot;Private Queues&quot;.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-NJaZy8Py2RU/U0JQaTZJzmI/AAAAAAAAAcg/djWY8wC96Y4/s1600/msmq.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-NJaZy8Py2RU/U0JQaTZJzmI/AAAAAAAAAcg/djWY8wC96Y4/s1600/msmq.png&quot; title=&quot;Computer management - msmq&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;strong&gt;Trouble shooting MSMQ&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;If the MSMQ queue objects are created with inappropriate credentials, you would have to delete the queue. There are 2 ways of doing that. &lt;br /&gt;&lt;ol&gt;&lt;li&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;In computer management, go to the security properties of the queue, take ownership through the advanced button, and set permissions to what you want.&amp;nbsp;&lt;/div&gt;&lt;/li&gt;&lt;li&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;Find the queue config file in the system32\msmq\storage\lqs directory and delete the file; the queue name will be inside the file you want. When you restart the MSMQ service, the queue will have disappeared. &lt;/div&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;Services&lt;/h3&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;&lt;div&gt;Before you start the service make sure you have added an AD user to the Log On for the service. &lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-s3cA2NIaPD0/U0JROspBM7I/AAAAAAAAAcw/0p1_hwfvqeY/s1600/serviceLogon.png&quot; height=&quot;400&quot; width=&quot;348&quot; /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;After you have installed and finished the configuration, then you can start the service.&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-feG8o9xIaYI/U0JQ8isePsI/AAAAAAAAAco/VAvfBPIwXi4/s1600/service1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-feG8o9xIaYI/U0JQ8isePsI/AAAAAAAAAco/VAvfBPIwXi4/s1600/service1.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If any trouble should occur you will be able to read more about the details in the Log. If the service doesn’t start and you don’t get any errors in the log it might be credential error. Then make sure you use the correct AD user and delete the “serverinternallog” instance in Private Queues, before restarting the service.&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Testing out inRiver with the Rich Client editor&lt;/h3&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0cm 0cm 10pt;&quot;&gt;When the inRiver Server is up and running you can connect to it with the inRiver Rich client editor.&lt;br /&gt;The installation procedure is very straight forward. Run installation file “Setup inRiver Rich Client”.&amp;nbsp; Proceed forward by clicking &quot;Next&quot; until the installation is finished. If you have installed this on the inRiver Server, you can use the “localhost:8080” to logon to the system. This require ofcourse that you have installed the Rich Client editor on the&amp;nbsp;inRiver Server.&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-DsfIwqtponY/U0JYF-qrPUI/AAAAAAAAAdA/3bZKqU0mhHw/s1600/rich-logon-screen.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-DsfIwqtponY/U0JYF-qrPUI/AAAAAAAAAdA/3bZKqU0mhHw/s1600/rich-logon-screen.png&quot; height=&quot;320&quot; width=&quot;207&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;clear: both; text-align: left;&quot;&gt;If you want to access the inRiver Server from outside the server you most likely would have to set a new Inbound rule in the inRiver server.&amp;nbsp;You will find that under Server Manager -&amp;gt;&amp;nbsp;Configuration -&amp;gt; Windows Firewall -&amp;gt; Inbound rules. Choose Port and specify 8080.&lt;br /&gt;&lt;br /&gt;You could then for example&amp;nbsp; use&amp;nbsp; &amp;lt;machinename or DNS: 8080&amp;gt; as the server address to be able to log on. Click on &quot;Test Connection&quot; to check if the connection work, if not, the inbound rule isn&#39;t setup correct.&lt;/div&gt;&lt;div style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;clear: both; text-align: left;&quot;&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-n0IWsSGU9DI/U0Z4_G_1RmI/AAAAAAAAAgs/Eo3IIXtvwjE/s1600/server-manager.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-n0IWsSGU9DI/U0Z4_G_1RmI/AAAAAAAAAgs/Eo3IIXtvwjE/s1600/server-manager.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div align=&quot;left&quot;&gt;When everything is in order you should be able to work inside the Rich Client editor.&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-41UItH8b1Eo/U0Z4bLKnAgI/AAAAAAAAAgk/xyK-t5XIMYg/s1600/InRiverEditor.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-41UItH8b1Eo/U0Z4bLKnAgI/AAAAAAAAAgk/xyK-t5XIMYg/s1600/InRiverEditor.png&quot; width=&quot;560&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&amp;nbsp;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;Next blog post will go more into depth on how you setup a connect&amp;nbsp;from the PIM solution to EPiServer Commerce:&amp;nbsp;&amp;nbsp;&lt;a href=&quot;http://sveinaandahl.blogspot.no/2014/04/how-to-connect-pim-system-to-episerver.html&quot;&gt;http://sveinaandahl.blogspot.no/2014/04/how-to-connect-pim-system-to-episerver.html&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2014/04/how-to-connect-pim-solution-to.html</guid>            <pubDate>Thu, 10 Apr 2014 13:31:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to install EPiServer Search for EPiServer CMS 7</title>            <link>http://sveinaandahl.blogspot.com/2013/06/how-to-install-episerver-search-for.html</link>            <description>&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;Linda Mohacsi wrote a very good blog post about  EPiServer Search functionality a&amp;nbsp;week ago ( Ref. &lt;a href=&quot;/link/98e6ccfbfd8248e8b9e89ffb20a35c26.aspx&quot;&gt;http://world.episerver.com/Blogs/Linda-Mohacsi/Dates/2013/6/The-built-in-EPiServer-search-functionality-described-in-a-non-technical-way&lt;/a&gt; ) and Paul Smith have also written a blog post about  FTS for EPiServer CMS 6 a few years back. I have lately been working on upgrading a large enterprise solution to EPiServer CMS 7, where I also had to upgrade the search to use EPiServer Search (lucene). &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;After running into a few problems, I thought it would be a good idea to blogg about this, since the information about EPiServer Search is very limited and fragmented on the web.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Installing EPIServer Seach&lt;/strong&gt;&lt;br /&gt; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-P7eLF5pW0o4/UcSoPJdSg_I/AAAAAAAAAak/R5h7nQQeDp0/s1600/install-2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://2.bp.blogspot.com/-P7eLF5pW0o4/UcSoPJdSg_I/AAAAAAAAAak/R5h7nQQeDp0/s400/install-2.jpg&quot; height=&quot;301&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;&lt;div align=&quot;left&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://2.bp.blogspot.com/-P7eLF5pW0o4/UcSoPJdSg_I/AAAAAAAAAak/R5h7nQQeDp0/s1600/install-2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;﻿&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;After you have installed EPiServer Search from Deployment Center, some elements have been added to your web.config, .dll files into bin folder and a new folder called IndexingService containing a file called IndexingService.svc. The .svc&amp;nbsp;file&amp;nbsp;should be include to your project before you recompiling.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Web.config&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;&lt;/div&gt;&lt;span style=&quot;font-family: &amp;quot;Helvetica Neue&amp;quot;, Arial, Helvetica, sans-serif;&quot;&gt;Elements that will be added during the install to your web.config :&lt;/span&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;configuration&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;configSections&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;section&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;episerver.search&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;EPiServer.Search.Configuration.SearchSection, EPiServer.ApplicationModules&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;section&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;episerver.packaging&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;EPiServer.Packaging.Configuration.EPiServerPackagingSection, EPiServer.Packaging&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;section&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;episerver.search.indexingservice&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;EPiServer.Search.IndexingService.Configuration.IndexingServiceSection, EPiServer.Search.IndexingService&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;If you need to setup with more then one binding per site, ex. mycompany.com and mycompany.no, you’ll need to add &amp;lt;serviceHostingEnviroment multipleSiteBindingEnable= ”true”&amp;gt;, as shown below.&amp;nbsp; This is not included in the default installation, so you would need to add this one yourself.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.serviceModel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;   &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;bindings&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;    &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;     &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;webHttpBinding&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;binding&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;IndexingServiceCustomBinding&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxBufferPoolSize&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;1073741824&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxReceivedMessageSize&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;2147483647&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxBufferSize&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;2147483647&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;readerQuotas&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxStringContentLength&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;10000000&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;webHttpBinding&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;bindings&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;serviceHostingEnvironment&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;aspNetCompatibilityEnabled&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot; style=&quot;background-color: yellow;&quot;&gt;multipleSiteBindingsEnabled&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.serviceModel&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;Default from installation, the baseUri would be setup with localhost. You would have to replace this with a correct dns name.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.search&lt;/span&gt; active=&quot;true&quot;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;namedIndexingServices&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;defaultService&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;serviceName&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;rem&quot;&gt;&amp;lt;!--&amp;lt;add name=&quot;{serviceName}&quot; baseUri=&quot;{indexingServiceBaseUri}&quot; accessKey=&quot;{accessKey}&quot;/&amp;gt;--&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;serviceName&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;baseUri&lt;/span&gt;&lt;span class=&quot;kwrd&quot; style=&quot;background-color: yellow;&quot;&gt;=&quot;http://www.xxxx.com/IndexingService/IndexingService.svc&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;accessKey&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;local&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;services&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;namedIndexingServices&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;searchResultFilter&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;defaultInclude&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;providers&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;searchResultFilter&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.search&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;The [appDataPath] is defined in EpiServerFrameWork.config. I would recomind to have the index as a subfolder in vpp. During installation of search you would have choose a place to put it.&lt;/span&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.packaging&lt;/span&gt; protectedVirtualPath=&quot;~/CMS/&quot; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.search.indexingservice&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;clients&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;rem&quot;&gt;&amp;lt;!--add name=&quot;example&quot; description=&quot;example&quot; ipAddress=&quot;127.0.0.1/8,192.168.0.0/24&quot; ip6Address=&quot;&quot; allowLocal=&quot;true|false&quot; readonly=&quot;true|false&quot; /--&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;local&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;local&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;allowLocal&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;true&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;readonly&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;false&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;rem&quot;&gt;&amp;lt;!--add name=&quot;example&quot; description=&quot;example&quot; ipAddress=&quot;127.0.0.1/8,192.168.0.0/24&quot; ip6Address=&quot;&quot; allowLocal=&quot;true|false&quot; readonly=&quot;true|false&quot; /--&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;clients&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;namedIndexes&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;defaultIndex&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;default&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;indexes&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;default&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;directoryPath&lt;/span&gt;&lt;span class=&quot;kwrd&quot; style=&quot;background-color: yellow;&quot;&gt;=&quot;[appDataPath]\Index&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;readonly&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;false&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;indexes&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;namedIndexes&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;episerver.search.indexingservice&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;location&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;IndexingService/IndexingService.svc&quot;&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;httpRuntime&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxQueryStringLength&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;65536&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.web&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.webServer&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;security&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;requestFiltering&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;requestLimits&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;maxQueryString&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;65536&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;        &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;requestFiltering&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;security&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;system.webServer&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kwrd&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Testing of the service&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;After you have installed the search and verified the web.config you can test if the service is running by type this url into a browser : http://www.xxxx.com/IndexingService/IndexingService.svc. Don’t worry about that the endpoint isn’t found, if it work it should look like this. If you don’t get this up read last chapter about other problems you could run into or your web.config isn’t correct modifed. &lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-N5GGa33Wvh0/UcSx4tF227I/AAAAAAAAAaw/WHX1VZ7vYKk/s1600/endpoint.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-N5GGa33Wvh0/UcSx4tF227I/AAAAAAAAAaw/WHX1VZ7vYKk/s1600/endpoint.png&quot; /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Indexing the site(s)&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;To my big surprise EPiServer got a hidden feature!  You can index the site, by typing this url into a browser: http://www.xxxx.no/EPiServer/CMS/Admin/IndexContent.aspx. &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://3.bp.blogspot.com/-g6SzteCJVz0/UcSyzmopoNI/AAAAAAAAAa8/jWVXa2xVLtM/s1600/Index-site-content.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://3.bp.blogspot.com/-g6SzteCJVz0/UcSyzmopoNI/AAAAAAAAAa8/jWVXa2xVLtM/s400/Index-site-content.jpg&quot; height=&quot;120&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;em&gt;(Tips from&amp;nbsp;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=66078&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;Fredrik Haglund&lt;/a&gt;&lt;/span&gt;)&lt;/em&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;If you open a file browser and navigate [appDataPath]\Index\main you will see that the files is started to be generated. So now you know its running. Depending of the size of the site, it could take some time to index it. For me it took about 20 min to index 6000 pages.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://1.bp.blogspot.com/-_iEXzN7fILI/UcS0XfWVbSI/AAAAAAAAAbM/XQyEiPYT2EY/s1600/Folder-index.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://1.bp.blogspot.com/-_iEXzN7fILI/UcS0XfWVbSI/AAAAAAAAAbM/XQyEiPYT2EY/s400/Folder-index.jpg&quot; height=&quot;276&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;&lt;strong&gt;Other problems you could run into&lt;/strong&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;If you got problems with that IIS isn’t recognize the svc file. You should check if WCF for .net framework 3.5 is installed.   &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;If you have upgraded an old EPiServer site which runs under .net framework 2.0, would be to check that you have added “svc-Integrated-4.0&quot; under &lt;system .webserver=&quot;&quot;&gt;&lt;handlers&gt; and removed the old one.&lt;/handlers&gt;&lt;/system&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;style type=&quot;text/css&quot;&gt;.csharpcode, .csharpcode pre {  font-size: small;  color: black;  font-family: Consolas, &quot;Courier New&quot;, Courier, Monospace;  background-color: #ffffff;  /*white-space: pre;*/ }  .csharpcode pre { margin: 0em; }  .csharpcode .rem { color: #008000; }  .csharpcode .kwrd { color: #0000ff; }  .csharpcode .str { color: #a31515; }  .csharpcode .op { color: #0000c0; }  .csharpcode .preproc { color: #cc6633; }  .csharpcode .asp { background-color: #ffff00; }  .csharpcode .html { color: #800000; }  .csharpcode .attr { color: #ff0000; }  .csharpcode .alt  {  background-color: #f4f4f4;  width: 100%;  margin: 0em; }  .csharpcode .lnum { color: #606060; } &lt;/style&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;svc-Integrated-4.0&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;*.svc&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;verb&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;preCondition&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;integratedMode,runtimeVersionv4.0&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Arial, Helvetica, sans-serif;&quot;&gt;A special feature you must check, if you are going to run on window 2012 server is to check if &#171;HTTP Activation&#187; under the feature .net framework 3.5 is enabled. Last tips are that you could also download the tool LUKE (&lt;a href=&quot;http://luke.codeplex.com/&quot;&gt;http://luke.codeplex.com/&lt;/a&gt;) to be able to analyze and maintain the lucene index. &lt;/span&gt;</description>            <guid>http://sveinaandahl.blogspot.com/2013/06/how-to-install-episerver-search-for.html</guid>            <pubDate>Thu, 27 Jun 2013 12:32:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to create new language codes that&#39;s not available in Manage Website Languages</title>            <link>http://sveinaandahl.blogspot.com/2011/07/how-to-create-new-language-codes-thats.html</link>            <description>Sometimes the operating system doesn&#39;t have all the language codes that you need on the server you run your EPiServer solution. One way to solve that, is to create an console application which you run on the server with argument for the new langauge code based on one language code that already exists on the server.&lt;br /&gt;&lt;br /&gt;Create a console application and copy this code:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Globalization;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; CreateLanguage&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;{    &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   9:  &lt;/span&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; CreateLanguage&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  10:  &lt;/span&gt;    { &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  11:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; CreateLanguage()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  12:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  13:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  14:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  15:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; CreateLanguage(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; inputLine)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  16:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  17:  &lt;/span&gt;            SetLanguage(inputLine);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  18:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  19:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  20:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; SetLanguage(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; inputLine)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  21:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  22:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(inputLine))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  23:  &lt;/span&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  24:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;[] LanguageCode = inputLine.Split(&lt;span class=&quot;str&quot;&gt;&#39;_&#39;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  25:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  26:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; copyLanguageId = LanguageCode[0];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  27:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; newLanguageId = LanguageCode[1];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  28:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; newLanguageName = LanguageCode[2];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  29:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  30:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Get the base culture and region information&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  31:  &lt;/span&gt;                CultureInfo cultureInfo = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CultureInfo(copyLanguageId.ToString());&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  32:  &lt;/span&gt;                RegionInfo regionInfo = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; RegionInfo(cultureInfo.Name);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  33:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  34:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Create a locale &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  35:  &lt;/span&gt;                CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CultureAndRegionInfoBuilder(newLanguageId.ToString(), CultureAndRegionModifiers.None);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  36:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  37:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Load the base culture and region information&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  38:  &lt;/span&gt;                cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  39:  &lt;/span&gt;                cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  40:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  41:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Set the culture name&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  42:  &lt;/span&gt;                cultureAndRegionInfoBuilder.CultureEnglishName = newLanguageName.ToString();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  43:  &lt;/span&gt;                cultureAndRegionInfoBuilder.CultureNativeName = newLanguageName.ToString();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  44:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  45:  &lt;/span&gt;                NumberFormatInfo nfi = cultureInfo.NumberFormat;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  46:  &lt;/span&gt;                &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  47:  &lt;/span&gt;                cultureAndRegionInfoBuilder.NumberFormat = nfi;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  48:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  49:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Register with your operating system&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  50:  &lt;/span&gt;                cultureAndRegionInfoBuilder.Register();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  51:  &lt;/span&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  52:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  53:  &lt;/span&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  54:  &lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;After compiling the code, then&amp;nbsp;run a command prompt under administrative priviledges, where you type something like this: CreateLanguage.exe &quot;en-EN&quot; &quot;en-RO&quot; &quot;English (Rom&#226;nia)&quot; &lt;br /&gt;&lt;br /&gt;Once you&#39;ve run this program, fire up EPiServer in Admin mode, select &#39;Manage Web Site languages&#39; from Config-tab, click &#39;Add language&#39; and the new local will be ready to use.&lt;br /&gt;&lt;br /&gt;PS: If you run EPiServer CMS 6 you will get a bug unless you write to EPiServer support and ask for a bug fixed EPiServer.dll. On EPiServer CMS 5 this works just fine. :-)</description>            <guid>http://sveinaandahl.blogspot.com/2011/07/how-to-create-new-language-codes-thats.html</guid>            <pubDate>Thu, 14 Jul 2011 00:27:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>How to create new language codes that&#39;s not available in Manage Website Languages</title>            <link>http://sveinaandahl.blogspot.com/2011/07/how-to-create-new-language-codes-thats.html</link>            <description>Sometimes the operating system doesn&#39;t have all the language codes that you need on the server you run your EPiServer solution. One way to solve that, is to create an console application which you run on the server with argument for the new langauge code based on one language code that already exists on the server.&lt;br /&gt;&lt;br /&gt;Create a console application and copy this code:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Collections.Generic;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Linq;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Text;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;using&lt;/span&gt; System.Globalization;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; CreateLanguage&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;{    &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   9:  &lt;/span&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; CreateLanguage&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  10:  &lt;/span&gt;    { &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  11:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; CreateLanguage()&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  12:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  13:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  14:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  15:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; CreateLanguage(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; inputLine)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  16:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  17:  &lt;/span&gt;            SetLanguage(inputLine);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  18:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  19:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  20:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; SetLanguage(&lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; inputLine)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  21:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  22:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(inputLine))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  23:  &lt;/span&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  24:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt;[] LanguageCode = inputLine.Split(&lt;span class=&quot;str&quot;&gt;&#39;_&#39;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  25:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  26:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; copyLanguageId = LanguageCode[0];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  27:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; newLanguageId = LanguageCode[1];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  28:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; newLanguageName = LanguageCode[2];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  29:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  30:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Get the base culture and region information&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  31:  &lt;/span&gt;                CultureInfo cultureInfo = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CultureInfo(copyLanguageId.ToString());&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  32:  &lt;/span&gt;                RegionInfo regionInfo = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; RegionInfo(cultureInfo.Name);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  33:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  34:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Create a locale &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  35:  &lt;/span&gt;                CultureAndRegionInfoBuilder cultureAndRegionInfoBuilder = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; CultureAndRegionInfoBuilder(newLanguageId.ToString(), CultureAndRegionModifiers.None);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  36:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  37:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Load the base culture and region information&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  38:  &lt;/span&gt;                cultureAndRegionInfoBuilder.LoadDataFromCultureInfo(cultureInfo);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  39:  &lt;/span&gt;                cultureAndRegionInfoBuilder.LoadDataFromRegionInfo(regionInfo);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  40:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  41:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Set the culture name&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  42:  &lt;/span&gt;                cultureAndRegionInfoBuilder.CultureEnglishName = newLanguageName.ToString();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  43:  &lt;/span&gt;                cultureAndRegionInfoBuilder.CultureNativeName = newLanguageName.ToString();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  44:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  45:  &lt;/span&gt;                NumberFormatInfo nfi = cultureInfo.NumberFormat;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  46:  &lt;/span&gt;                &lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  47:  &lt;/span&gt;                cultureAndRegionInfoBuilder.NumberFormat = nfi;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  48:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  49:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//* Register with your operating system&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  50:  &lt;/span&gt;                cultureAndRegionInfoBuilder.Register();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  51:  &lt;/span&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  52:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  53:  &lt;/span&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  54:  &lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;After compiling the code, then&amp;nbsp;run a command prompt under administrative priviledges, where you type something like this: CreateLanguage.exe &quot;en-EN&quot; &quot;en-RO&quot; &quot;English (Rom&#226;nia)&quot; &lt;br /&gt;&lt;br /&gt;Once you&#39;ve run this program, fire up EPiServer in Admin mode, select &#39;Manage Web Site languages&#39; from Config-tab, click &#39;Add language&#39; and the new local will be ready to use.&lt;br /&gt;&lt;br /&gt;PS: If you run EPiServer CMS 6 you will get a bug unless you write to EPiServer support and ask for a bug fixed EPiServer.dll. On EPiServer CMS 5 this works just fine. :-)</description>            <guid>http://sveinaandahl.blogspot.com/2011/07/how-to-create-new-language-codes-thats.html</guid>            <pubDate>Thu, 14 Jul 2011 00:27:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>Robots.txt enterprise version for EPiServer CMS</title>            <link>http://sveinaandahl.blogspot.com/2011/07/robotstxt-enterprise-version-for.html</link>            <description>Adding robots.txt file to a single site is easy. To do the samething for an enterprise version is a bit more work. The easiest way to solve the challange is to add an HttpHandler that write out the correct content based on the url of the sites. The example code below get the content from files that is stored in&amp;nbsp; /Global/Robots/ in filemanager, but you could easly change it&amp;nbsp;to a different path.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Under the /Global/Robots&amp;nbsp;folder you add files&amp;nbsp;that is simular to this:&amp;nbsp;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;mysite.com_robots.txt &lt;/li&gt;&lt;li&gt;mysite2.com_robots.txt&lt;/li&gt;&lt;/ul&gt;Also add an default_robots.txt to have a fallback version. Read here to get an idea how to write the content of the robots.text file, &lt;a href=&quot;http://www.robotstxt.org/robotstxt.html&quot;&gt;robotstxt.org&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Create a class and add this code:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; Common.CoreLibrary.Robots&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; RobotsHandler : IHttpHandler&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; ProcessRequest(HttpContext context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; path = context.Request.Url.DnsSafeHost;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   9:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  10:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt;( path.Contains(&lt;span class=&quot;str&quot;&gt;&quot;www.&quot;&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  11:  &lt;/span&gt;                path = path.Replace(&lt;span class=&quot;str&quot;&gt;&quot;www.&quot;&lt;/span&gt;,&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  13:  &lt;/span&gt;            path = &lt;span class=&quot;str&quot;&gt;&quot;/Global/Robots/&quot;&lt;/span&gt; + path + &lt;span class=&quot;str&quot;&gt;&quot;_robots.txt&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  14:  &lt;/span&gt;            UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(path) &lt;span class=&quot;kwrd&quot;&gt;as&lt;/span&gt; UnifiedFile;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  15:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  16:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (file != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  17:  &lt;/span&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  18:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (context.Request.ServerVariables[&lt;span class=&quot;str&quot;&gt;&quot;Https&quot;&lt;/span&gt;] == &lt;span class=&quot;str&quot;&gt;&quot;off&quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  19:  &lt;/span&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  20:  &lt;/span&gt;                    &lt;span class=&quot;rem&quot;&gt;//Read spesific file for each brand&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  21:  &lt;/span&gt;                    Outfile(context, file);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  22:  &lt;/span&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  23:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  24:  &lt;/span&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  25:  &lt;/span&gt;                    &lt;span class=&quot;rem&quot;&gt;// HTTPS&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  26:  &lt;/span&gt;                    context.Response.ContentType = &lt;span class=&quot;str&quot;&gt;&quot;text/plain&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  27:  &lt;/span&gt;                    context.Response.Write(&lt;span class=&quot;str&quot;&gt;&quot;User-agent: *\n&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  28:  &lt;/span&gt;                    context.Response.Write(&lt;span class=&quot;str&quot;&gt;&quot;Disallow: /&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  29:  &lt;/span&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  30:  &lt;/span&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  31:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  32:  &lt;/span&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  33:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//Backup file if not the spesific robots.txt exits.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  34:  &lt;/span&gt;                path = &lt;span class=&quot;str&quot;&gt;&quot;/Global/Robots/default_robots.txt&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  35:  &lt;/span&gt;                file = HostingEnvironment.VirtualPathProvider.GetFile(path) &lt;span class=&quot;kwrd&quot;&gt;as&lt;/span&gt; UnifiedFile;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  36:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  37:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (file == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;) &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  38:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  39:  &lt;/span&gt;                Outfile(context, file);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  40:  &lt;/span&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  41:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  42:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  43:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Outfile(HttpContext context, UnifiedFile file)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  44:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  45:  &lt;/span&gt;            Stream sourceFile = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  46:  &lt;/span&gt;            context.Response.ContentEncoding = Encoding.UTF8;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  47:  &lt;/span&gt;            context.Response.ContentType = &lt;span class=&quot;str&quot;&gt;&quot;text/plain&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  48:  &lt;/span&gt;            &lt;span class=&quot;rem&quot;&gt;//Write the file directly to the HTTP content output stream. &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  49:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; FileSize;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  50:  &lt;/span&gt;            FileSize = sourceFile.Length;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  51:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] getContent = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;)FileSize];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  52:  &lt;/span&gt;            sourceFile.Read(getContent, 0, (&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;)sourceFile.Length);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  53:  &lt;/span&gt;            sourceFile.Close();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  54:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  55:  &lt;/span&gt;            context.Response.BinaryWrite(getContent);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  56:  &lt;/span&gt;            context.Response.End();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  57:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  58:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  59:  &lt;/span&gt;        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; IHttpHandler Members&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  60:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  61:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; IsReusable&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  62:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  63:  &lt;/span&gt;            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  64:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  65:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  66:  &lt;/span&gt;        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  67:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  68:  &lt;/span&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  69:  &lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Add the following line to the web.config after &amp;lt;system.webServer&amp;gt;&amp;lt;handlers&amp;gt;:&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Robots&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;/robots.txt&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;verb&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Common.CoreLibrary.Robots.RobotsHandler&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;resourceType&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Unspecified&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;requireAccess&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Script&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;So next time you write mysite.com/robots.txt or mysite2.com/robots.txt you should recive different content. :-)</description>            <guid>http://sveinaandahl.blogspot.com/2011/07/robotstxt-enterprise-version-for.html</guid>            <pubDate>Wed, 13 Jul 2011 23:27:00 GMT</pubDate>           <category>Blog post</category></item><item> <title>Robots.txt enterprise version for EPiServer CMS</title>            <link>http://sveinaandahl.blogspot.com/2011/07/robotstxt-enterprise-version-for.html</link>            <description>Adding robots.txt file to a single site is easy. To do the samething for an enterprise version is a bit more work. The easiest way to solve the challange is to add an HttpHandler that write out the correct content based on the url of the sites. The example code below get the content from files that is stored in&amp;nbsp; /Global/Robots/ in filemanager, but you could easly change it&amp;nbsp;to a different path.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;Under the /Global/Robots&amp;nbsp;folder you add files&amp;nbsp;that is simular to this:&amp;nbsp;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;mysite.com_robots.txt &lt;/li&gt;&lt;li&gt;mysite2.com_robots.txt&lt;/li&gt;&lt;/ul&gt;Also add an default_robots.txt to have a fallback version. Read here to get an idea how to write the content of the robots.text file, &lt;a href=&quot;http://www.robotstxt.org/robotstxt.html&quot;&gt;robotstxt.org&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Create a class and add this code:&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;csharpcode&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   1:  &lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;namespace&lt;/span&gt; Common.CoreLibrary.Robots&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   2:  &lt;/span&gt;{&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   3:  &lt;/span&gt;    &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;class&lt;/span&gt; RobotsHandler : IHttpHandler&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   4:  &lt;/span&gt;    {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   5:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   6:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; ProcessRequest(HttpContext context)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   7:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   8:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;string&lt;/span&gt; path = context.Request.Url.DnsSafeHost;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;   9:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  10:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt;( path.Contains(&lt;span class=&quot;str&quot;&gt;&quot;www.&quot;&lt;/span&gt;))&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  11:  &lt;/span&gt;                path = path.Replace(&lt;span class=&quot;str&quot;&gt;&quot;www.&quot;&lt;/span&gt;,&lt;span class=&quot;str&quot;&gt;&quot;&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  12:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  13:  &lt;/span&gt;            path = &lt;span class=&quot;str&quot;&gt;&quot;/Global/Robots/&quot;&lt;/span&gt; + path + &lt;span class=&quot;str&quot;&gt;&quot;_robots.txt&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  14:  &lt;/span&gt;            UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(path) &lt;span class=&quot;kwrd&quot;&gt;as&lt;/span&gt; UnifiedFile;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  15:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  16:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (file != &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  17:  &lt;/span&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  18:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (context.Request.ServerVariables[&lt;span class=&quot;str&quot;&gt;&quot;Https&quot;&lt;/span&gt;] == &lt;span class=&quot;str&quot;&gt;&quot;off&quot;&lt;/span&gt;)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  19:  &lt;/span&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  20:  &lt;/span&gt;                    &lt;span class=&quot;rem&quot;&gt;//Read spesific file for each brand&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  21:  &lt;/span&gt;                    Outfile(context, file);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  22:  &lt;/span&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  23:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  24:  &lt;/span&gt;                {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  25:  &lt;/span&gt;                    &lt;span class=&quot;rem&quot;&gt;// HTTPS&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  26:  &lt;/span&gt;                    context.Response.ContentType = &lt;span class=&quot;str&quot;&gt;&quot;text/plain&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  27:  &lt;/span&gt;                    context.Response.Write(&lt;span class=&quot;str&quot;&gt;&quot;User-agent: *\n&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  28:  &lt;/span&gt;                    context.Response.Write(&lt;span class=&quot;str&quot;&gt;&quot;Disallow: /&quot;&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  29:  &lt;/span&gt;                }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  30:  &lt;/span&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  31:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;else&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  32:  &lt;/span&gt;            {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  33:  &lt;/span&gt;                &lt;span class=&quot;rem&quot;&gt;//Backup file if not the spesific robots.txt exits.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  34:  &lt;/span&gt;                path = &lt;span class=&quot;str&quot;&gt;&quot;/Global/Robots/default_robots.txt&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  35:  &lt;/span&gt;                file = HostingEnvironment.VirtualPathProvider.GetFile(path) &lt;span class=&quot;kwrd&quot;&gt;as&lt;/span&gt; UnifiedFile;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  36:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  37:  &lt;/span&gt;                &lt;span class=&quot;kwrd&quot;&gt;if&lt;/span&gt; (file == &lt;span class=&quot;kwrd&quot;&gt;null&lt;/span&gt;) &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  38:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  39:  &lt;/span&gt;                Outfile(context, file);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  40:  &lt;/span&gt;            }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  41:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  42:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  43:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;void&lt;/span&gt; Outfile(HttpContext context, UnifiedFile file)&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  44:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  45:  &lt;/span&gt;            Stream sourceFile = file.Open(FileMode.Open, FileAccess.Read, FileShare.Read);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  46:  &lt;/span&gt;            context.Response.ContentEncoding = Encoding.UTF8;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  47:  &lt;/span&gt;            context.Response.ContentType = &lt;span class=&quot;str&quot;&gt;&quot;text/plain&quot;&lt;/span&gt;;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  48:  &lt;/span&gt;            &lt;span class=&quot;rem&quot;&gt;//Write the file directly to the HTTP content output stream. &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  49:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;long&lt;/span&gt; FileSize;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  50:  &lt;/span&gt;            FileSize = sourceFile.Length;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  51:  &lt;/span&gt;            &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[] getContent = &lt;span class=&quot;kwrd&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;byte&lt;/span&gt;[(&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;)FileSize];&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  52:  &lt;/span&gt;            sourceFile.Read(getContent, 0, (&lt;span class=&quot;kwrd&quot;&gt;int&lt;/span&gt;)sourceFile.Length);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  53:  &lt;/span&gt;            sourceFile.Close();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  54:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  55:  &lt;/span&gt;            context.Response.BinaryWrite(getContent);&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  56:  &lt;/span&gt;            context.Response.End();&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  57:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  58:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  59:  &lt;/span&gt;        &lt;span class=&quot;preproc&quot;&gt;#region&lt;/span&gt; IHttpHandler Members&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  60:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  61:  &lt;/span&gt;        &lt;span class=&quot;kwrd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;bool&lt;/span&gt; IsReusable&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  62:  &lt;/span&gt;        {&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  63:  &lt;/span&gt;            get { &lt;span class=&quot;kwrd&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;false&lt;/span&gt;; }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  64:  &lt;/span&gt;        }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  65:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  66:  &lt;/span&gt;        &lt;span class=&quot;preproc&quot;&gt;#endregion&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  67:  &lt;/span&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  68:  &lt;/span&gt;    }&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;lnum&quot;&gt;  69:  &lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Add the following line to the web.config after &amp;lt;system.webServer&amp;gt;&amp;lt;handlers&amp;gt;:&lt;br /&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code&gt;&lt;span class=&quot;kwrd&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;html&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Robots&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;/robots.txt&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;verb&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;*&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Common.CoreLibrary.Robots.RobotsHandler&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;resourceType&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Unspecified&quot;&lt;/span&gt; &lt;span class=&quot;attr&quot;&gt;requireAccess&lt;/span&gt;&lt;span class=&quot;kwrd&quot;&gt;=&quot;Script&quot;&lt;/span&gt; &lt;span class=&quot;kwrd&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;So next time you write mysite.com/robots.txt or mysite2.com/robots.txt you should recive different content. :-)</description>            <guid>http://sveinaandahl.blogspot.com/2011/07/robotstxt-enterprise-version-for.html</guid>            <pubDate>Wed, 13 Jul 2011 23:27:00 GMT</pubDate>           <category>Blog post</category></item></channel>
</rss>