diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json
index 0623babb8a..9528b98a3c 100644
--- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json
+++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json
@@ -34,7 +34,7 @@
]
},
{
- "condition": "(!OrganizationalAuth)",
+ "condition": "(!OrganizationalAuth && !IndividualB2CAuth)",
"exclude": [
"Controllers/**",
"Pages/Account/**",
@@ -78,12 +78,6 @@
"exclude": [
"Extensions/AzureAdB2C*.cs"
]
- },
- {
- "condition": "(!OrganizationalAuth || !IndividualB2CAuth)",
- "exclude": [
- "Controllers/AccountController.cs"
- ]
}
]
}
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml
new file mode 100644
index 0000000000..cc15816741
--- /dev/null
+++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml
@@ -0,0 +1,10 @@
+@page
+@model AccessDeniedModel
+@{
+ ViewData["Title"] = "Access denied";
+}
+
+
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs
new file mode 100644
index 0000000000..b5ed3d9c4a
--- /dev/null
+++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/RazorPagesWeb-CSharp/Pages/Account/AccessDenied.cshtml.cs
@@ -0,0 +1,11 @@
+using Microsoft.AspNetCore.Mvc.RazorPages;
+
+namespace Company.WebApplication1.Pages.Account
+{
+ public class AccessDeniedModel : PageModel
+ {
+ public void OnGet()
+ {
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/.template.config/template.json b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/.template.config/template.json
index b8214923fd..5b5ac1ae62 100644
--- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/.template.config/template.json
+++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/.template.config/template.json
@@ -33,7 +33,7 @@
]
},
{
- "condition": "(!IndividualAuth && !OrganizationalAuth)",
+ "condition": "(!IndividualAuth && !OrganizationalAuth && !IndividualB2CAuth)",
"exclude": [
"Controllers/AccountController.cs",
"Views/Account/**",
diff --git a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs
index 7f3e1465f6..c364589451 100644
--- a/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs
+++ b/src/Microsoft.DotNet.Web.ProjectTemplates/content/StarterWeb-CSharp/Controllers/AccountController.cs
@@ -1,24 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
-#if (IndividualAuth)
-using System.Security.Claims;
-#endif
using System.Threading.Tasks;
-#if (OrganizationalAuth || IndividualB2CAuth || IndividualAuth)
-using Microsoft.AspNetCore.Authentication;
-#endif
#if (OrganizationalAuth || IndividualB2CAuth)
+using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
#endif
-#if (IndividualAuth)
-using Microsoft.AspNetCore.Authorization;
-#endif
using Microsoft.AspNetCore.Mvc;
-#if (IndividualAuth)
-using Microsoft.AspNetCore.Mvc.Rendering;
-using Microsoft.Extensions.Logging;
+#if (IndividualB2CAuth)
using Microsoft.Extensions.Options;
#endif
@@ -31,35 +21,23 @@ namespace Company.WebApplication1.Controllers
[HttpGet]
public IActionResult SignIn()
{
- var redirectUrl = Url.Action(nameof(HomeController.Index), "Home");
+ var redirectUrl = Url.Page("/Index");
return Challenge(
new AuthenticationProperties { RedirectUri = redirectUrl },
- OpenIdConnectDefaults.AuthenticationScheme);
+ OpenIdConnectDefaults.AuthenticationScheme
+ );
}
[HttpGet]
public IActionResult SignOut()
{
- var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme);
+ var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme);
return SignOut(
new AuthenticationProperties { RedirectUri = callbackUrl },
- CookieAuthenticationDefaults.AuthenticationScheme,
- OpenIdConnectDefaults.AuthenticationScheme);
+ CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme
+ );
}
-
- [HttpGet]
- public IActionResult SignedOut()
- {
- if (User.Identity.IsAuthenticated)
- {
- // Redirect to home page if the user is authenticated.
- return RedirectToAction(nameof(HomeController.Index), "Home");
- }
-
- return View();
- }
-#endif
-#if (IndividualB2CAuth)
+#elseif (IndividualB2CAuth)
private readonly AzureAdB2COptions _options;
public AccountController(IOptions b2cOptions)
@@ -70,16 +48,17 @@ namespace Company.WebApplication1.Controllers
[HttpGet]
public IActionResult SignIn()
{
- var redirectUrl = Url.Action(nameof(HomeController.Index), "Home");
+ var redirectUrl = Url.Page("/Index");
return Challenge(
new AuthenticationProperties { RedirectUri = redirectUrl },
- OpenIdConnectDefaults.AuthenticationScheme);
+ OpenIdConnectDefaults.AuthenticationScheme
+ );
}
[HttpGet]
public IActionResult ResetPassword()
{
- var redirectUrl = Url.Action(nameof(HomeController.Index), "Home");
+ var redirectUrl = Url.Page("/Index");
var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.ResetPasswordPolicyId;
return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme);
@@ -88,7 +67,7 @@ namespace Company.WebApplication1.Controllers
[HttpGet]
public IActionResult EditProfile()
{
- var redirectUrl = Url.Action(nameof(HomeController.Index), "Home");
+ var redirectUrl = Url.Page("/Index");
var properties = new AuthenticationProperties { RedirectUri = redirectUrl };
properties.Items[AzureAdB2COptions.PolicyAuthenticationProperty] = _options.EditProfilePolicyId;
return Challenge(properties, OpenIdConnectDefaults.AuthenticationScheme);
@@ -97,21 +76,12 @@ namespace Company.WebApplication1.Controllers
[HttpGet]
public IActionResult SignOut()
{
- var callbackUrl = Url.Action(nameof(SignedOut), "Account", values: null, protocol: Request.Scheme);
- return SignOut(new AuthenticationProperties { RedirectUri = callbackUrl },
- CookieAuthenticationDefaults.AuthenticationScheme, OpenIdConnectDefaults.AuthenticationScheme);
- }
-
- [HttpGet]
- public IActionResult SignedOut()
- {
- if (User.Identity.IsAuthenticated)
- {
- // Redirect to home page if the user is authenticated.
- return RedirectToAction(nameof(HomeController.Index), "Home");
- }
-
- return View();
+ var callbackUrl = Url.Page("/Account/SignedOut", pageHandler: null, values: null, protocol: Request.Scheme);
+ return SignOut(
+ new AuthenticationProperties { RedirectUri = callbackUrl },
+ CookieAuthenticationDefaults.AuthenticationScheme,
+ OpenIdConnectDefaults.AuthenticationScheme
+ );
}
#endif
@@ -121,4 +91,4 @@ namespace Company.WebApplication1.Controllers
return View();
}
}
-}
+}
\ No newline at end of file