Click here to Skip to main content
15,884,099 members
Home / Discussions / ASP.NET
   

ASP.NET

 
Questiongridview with dynamic dropdownlist control null exception Pin
Anand Solomon11-Nov-19 4:41
Anand Solomon11-Nov-19 4:41 
Questionvideo calling in asp.net Pin
Member 146439065-Nov-19 18:37
Member 146439065-Nov-19 18:37 
AnswerRe: video calling in asp.net Pin
F-ES Sitecore6-Nov-19 1:04
professionalF-ES Sitecore6-Nov-19 1:04 
AnswerRe: video calling in asp.net Pin
Blikkies6-Nov-19 1:28
professionalBlikkies6-Nov-19 1:28 
Questioni want show page numbers in bottom of the page like <1 2 3 4 5.......10 11 12> but it shows <1 2 3 4 5 6 to total> Pin
Member 134445211-Nov-19 20:17
Member 134445211-Nov-19 20:17 
AnswerRe: i want show page numbers in bottom of the page like <1 2 3 4 5.......10 11 12> but it shows <1 2 3 4 5 6 to total> Pin
Richard Deeming3-Nov-19 22:33
mveRichard Deeming3-Nov-19 22:33 
QuestionASP.Net Core Identity Pin
Mycroft Holmes28-Oct-19 13:11
professionalMycroft Holmes28-Oct-19 13:11 
AnswerRe: ASP.Net Core Identity Pin
jkirkerx30-Oct-19 13:10
professionaljkirkerx30-Oct-19 13:10 
I'm probably way off on this one. I haven't worked on this subject in over 3 years and I was using MVC, not .Net Core 3.0.

I understand the JWT Token and how it works, but thought that was for frameworks like Angular, React, Vue, where you just write the token in a cookie or Local Storage. I use JWT currently and can do OAuth2 with Google in my Angular project.

To the best of my knowledge, and I did a lot of research on this subject because I didn't want to use Microsoft Identity and get wrapped up in it's complex authentication methods. But the way I understood Microsoft.Identity was that under the hood, it took care of a lot of stuff in the background. Stuff like OAuth2 into Google, Facebook for alternative methods of sign in credentials other than the typical ones we make. But I'm not clear on it's life cycle and how it reloads Identity on every page cycle.

So I used GenericIdentity from System.Security.Principals. I could create a new Identity, store all the stuff I need in it, and it would trickle down to the Controller, View and Razor. But the caveat was that it had a short lifespan of 1 page cycle. So my code had to be wrapped in a custom controller attribute on each page I wanted to be secure.

So the user logs in, you generate the JWT token, create a fresh Identity, and then when you redirect to the next page and the Identity is blank and authenticated is false.

Code sample to clarify my work around:
Controller action with my AdminSecurityCheck attribute
[HttpGet]
[AdminSecurityCheck]
[Route("{userName}/Messages/{page?}/{id?}/{q?}/{s?}")]
public IActionResult Messages(int? page, int? id, string q, int? s)
Simple Attribute Code
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class AdminCheckAttribute : ActionFilterAttribute, IActionFilter
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var controller = filterContext.Controller as Controller;
        var httpContext = controller.HttpContext;

        Model_Admin_Login pResult = SecurityCookies.CookieRead_Admin_Login(httpContext);
        if (pResult.AccountName != null)
        {<br />
            Model_Admin_Login model = new Model_Admin_Login();
            bool result = EF_Website_Users.AdminCheck_AccountName(pResult.AccountName, ref model);
            if (result)
            {
                // Program the HttpContext.Current
                // This will persist for the current cycle only
                String[] newRoles = { "Administrator" };
                GenericIdentity newIdentity = new GenericIdentity(pResult.AccountName);
                GenericPrincipal newPrincipal = new GenericPrincipal(newIdentity, newRoles);
                httpContext.User = newPrincipal;
                System.Threading.Thread.CurrentPrincipal = httpContext.User;

                // Store the Global ViewData to Show the Admin Menu or Not<br />
                controller.ViewData["Admin_Menu"] = true;
                controller.ViewData["Admin_UserID"] = model.ID;
                controller.ViewData["Admin_UserName"] = pResult.AccountName.ToLower();
                controller.ViewData["Admin_ImageUrl"] = model.Avatar.Url;
                controller.ViewData["Admin_ImageAlt"] = model.Avatar.Alt;
                controller.ViewData["Admin_Base64"] = model.Avatar.Data != null ? Convert.ToBase64String(model.Avatar.Data, 0, model.Avatar.Data.Length) : null;

            }
            else
            {
                controller.ViewData["Admin_Menu"] = false;
            }<br />
        }
        else
        {
            controller.ViewData["Admin_Menu"] = false;<br />
        }

        base.OnActionExecuting(filterContext);
    }        

}
If it ain't broke don't fix it
Discover my world at jkirkerx.com

GeneralRe: ASP.Net Core Identity Pin
Mycroft Holmes31-Oct-19 11:13
professionalMycroft Holmes31-Oct-19 11:13 
GeneralRe: ASP.Net Core Identity Pin
jkirkerx1-Nov-19 12:23
professionaljkirkerx1-Nov-19 12:23 
QuestionImporting Rows Into a List Pin
ibrahimayhans28-Oct-19 0:37
ibrahimayhans28-Oct-19 0:37 
QuestionASP maker 2018 Pin
Member 1292025327-Oct-19 11:23
Member 1292025327-Oct-19 11:23 
AnswerRe: ASP maker 2018 Pin
Richard MacCutchan27-Oct-19 22:19
mveRichard MacCutchan27-Oct-19 22:19 
QuestionDraw Shape in Canvas Pin
John_Ryder26-Oct-19 1:58
John_Ryder26-Oct-19 1:58 
AnswerRe: Draw Shape in Canvas Pin
Afzaal Ahmad Zeeshan26-Oct-19 9:19
professionalAfzaal Ahmad Zeeshan26-Oct-19 9:19 
GeneralRe: Draw Shape in Canvas Pin
John_Ryder29-Oct-19 19:49
John_Ryder29-Oct-19 19:49 
AnswerRe: Draw Shape in Canvas Pin
jkirkerx28-Oct-19 12:53
professionaljkirkerx28-Oct-19 12:53 
QuestionHow do i make my detailsviewmodel work Pin
Stefaneus22-Oct-19 6:31
Stefaneus22-Oct-19 6:31 
AnswerRe: How do i make my detailsviewmodel work Pin
jkirkerx23-Oct-19 10:54
professionaljkirkerx23-Oct-19 10:54 
QuestionHow do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus21-Oct-19 14:49
Stefaneus21-Oct-19 14:49 
AnswerRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 1:00
mveRichard Deeming22-Oct-19 1:00 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus22-Oct-19 5:02
Stefaneus22-Oct-19 5:02 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 5:14
mveRichard Deeming22-Oct-19 5:14 
GeneralRe: How do i make a bootstrap carousel work with Asp.net core Razor Pin
Stefaneus22-Oct-19 7:04
Stefaneus22-Oct-19 7:04 
Answer[REPOST] How do i make a bootstrap carousel work with Asp.net core Razor Pin
Richard Deeming22-Oct-19 1:03
mveRichard Deeming22-Oct-19 1:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.