|
|
I have a datatable like this
----------------------------
STID NAME DOB SBCD
----------------------------
1001 XXX DMY AAAA
1001 XXX DMY BBBB
1001 XXX DMY CCCC
1001 XXX DMY DDDD
1002 YYY DMY AAAA
1002 YYY DMY BBBB
1002 YYY DMY CCCC
1003 ZZZ DMY AAAA
1003 ZZZ DMY BBBB
1003 ZZZ DMY CCCC
1003 ZZZ DMY DDDD
1003 ZZZ DMY EEEE
I want to convert this datatable into following format and bind it to gridview.
----------------------------------------------------------------------
| STID | NAME / DOB | SUBJECTS |
|------|----------------|--------------------------------------------|
|1001 | XXX | AAAA BBBB CCCC DDDD |
| | DMY | |
|------|----------------|--------------------------------------------|
|1002 | YYY | AAAA BBBB CCCC |
| | DMY | |
|------|----------------|--------------------------------------------|
|1003 | ZZZ | AAAA BBBB CCCC DDDD EEEE |
| | DOB | |
|------|----------------|--------------------------------------------|
|
|
|
|
|
Hi Friends,
I have web application along with few Class Library Projects.
I need help in implementing the following 2 points.
i) I have method written in Master Page code behind, I need to access this method from all my content pages.
ii) I need to access Master Page (like this.Master) from my another Code library project in the same Solution.
Kindly suggest on the solution.
Thanks in Advance,
Regards,
Priya.
|
|
|
|
|
If you use the MasterType directive it will let you use strongly-typed master pages. If your master page is;
using System.Web.UI;
namespace WebApplication1
{
public partial class SiteMaster : MasterPage
{
public string SayHello()
{
return "Hello";
}
}
}
Add the MasterType directive to the top of your content page
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" EnableEventValidation="false" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<%@ MasterType TypeName="WebApplication1.SiteMaster" %>
In your page you can now access the "SayHello" function on your master page
protected void Page_Load(object sender, EventArgs e)
{
string text = Master.SayHello();
}
If you don't want to use the MasterType you can still acccess the master page code but you have to cast yourself
var master = (SiteMaster) Master;
string text = master.SayHello();
If you have code in the master page that you need to access from non-page classes then the master page is the wrong place for that code. Put it in its own class rather than the master page.
|
|
|
|
|
Thank you so much.
I will try this.
Yes I have code 2 methods in Master page, which i need to access from content pages, But i will have more than 50 Content Pages. So i am planning to declare in Master and call from other pages.
What will be the best approach for this.
Actually I am thinking to write the methods in Class Library and access from all the aspx.cs pages. But the methods are calling one of the control in the Master page like this.Master.CtrlName. But this i couldnt write in my class library class file.
Thanks Again.
|
|
|
|
|
Add an interface to your class library which exposes the relevant methods.
Have the methods in your class library take an instance of that interface as a parameter, and call the methods on it.
Make the master page implement that interface.
Pass the master page to the class library methods.
Class library:
public interface ISiteMaster
{
void DoSomething();
string ReturnSomething();
}
public class SomeClass
{
public string Foo(ISiteMaster master)
{
master.DoSomething();
return master.ReturnSomething();
}
} Web application:
public partial class SiteMaster : MasterPage, ISiteMaster
{
public void DoSomething() { ... }
public string ReturnSomething() { ... }
}
public partial class HomePage : Page
{
protected void Page_Load(object sender, EventArgs e)
{
var helper = new SomeClass();
string value = helper.Foo(Master);
string value = helper.Foo((ISiteMaster)Master);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello Friends,
I have asp.net website and have few class libraries in the same solution.
I am trying to store a database retrieved datatable (it contains only one column) into Array variable and assigning the array into Session.
This code is in my aspx.cs page.
<b>Code is aspx.cs below:</b>
DataRow[] foundAuthors = dtPermission.Select("Value = '" + Permission + "'");
if (foundAuthors.Length != 0)
{
ArrayList permlist = new ArrayList();
foreach (DataRow dr in dtPermission.Rows)
{
permlist.Add(dr["Value"].ToString());
}
SessionHandler s = new SessionHandler();
s.SetSession(permlist, "sPermList");
I have the following code in the class library. But in this code the session value i am not sure how to assign as array list in test method. currently it is showing as string and not working. Please help.
<b>Class Library Code:</b>
public class SessionHandler : IRequiresSessionState
{
public SessionHandler() { }
public object GetSession(string key)
{
object session = HttpContext.Current.Session[key];
return session;
}
public void SetSession(object data, string key)
{
HttpContext.Current.Session.Add(key, data);
}
public bool Test(string sessionKey,string perValue)
{
string ss = GetSession(sessionKey).ToString();
--Here need to assign session value to array list and compare the perValue against array list (or) if we can directly compare session stored value and return true / false
return true;
}
}
Thanks in Advance,
Priya.
-- modified 14-Nov-19 6:23am.
|
|
|
|
|
How about:
public bool Test(string sessionKey, string perValue)
{
System.Collections.IEnumerable list = (System.Collections.IEnumerable)GetSession(sessionKey);
foreach (string item in list)
{
if (item == perValue)
{
return true;
}
}
return false;
} NB: You should avoid using ArrayList . It's an old collection from before the introduction of generics. Use List<T> instead.
NB2: The IRequiresSessionState on your SessionHandler class won't make any difference. That interface is only used on the IHttpHandler which handles the request. For a WebForms page, that is controlled by setting the EnableSessionState property in the <%@ Page ... %> directive.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello Richard,
Thanks lot and lot. It worked like charm!! This is saved my time, i was searching for a day on this.
Reg. the Note 1 : I agree and follow that.
Reg. the Note 2, I am not really understanding, if you could elaborate that will be great help to me. Is the approach I am following will hit performance,
Thanks in Advance.
Priya.
|
|
|
|
|
Every request to your application is handled by an instance of a class which implements the IHttpHandler interface[^].
For a WebForms page (.aspx ), that class will be derived from the System.Web.UI.Page class[^]. Session state is controlled by setting the EnableSessionState attribute on the @ Page directive[^]. It can be set to "True", "False", or "ReadOnly". The compiler will automatically implement the correct session state interface on the generated class for you.
For other handlers, session state is enabled or disabled depending on whether the handler class implements the IRequiresSessionState interface[^], or the IReadOnlySessionState interface[^] if it doesn't add or update any session data.
Implementing the IRequiresSessionState interface in a class which is not the handler for the current request will have no effect.
ASP.NET Session State Overview | Microsoft Docs[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thank you for brief explanation.
|
|
|
|
|
what is major difference between blazor server app and asp.net mvc razor app?
=====================================================
The grass is always greener on the other side of the fence
|
|
|
|
|
|
every interaction is a network call
if i have slow internet then basic functions will take forever to execute
=====================================================
The grass is always greener on the other side of the fence
|
|
|
|
|
My take on it was that with Blazer, you can make client side apps sort of like Angular, in which you can type your client side code in c# instead of JavaScript or TypeScript, and a Blazer utility sort of like Babel will translate your c# code into current and backwards compatible JavaScript, and automatically insert it into the server side generated HTML, and transmit it back to the client.
This reminds of .Net MVC, in which you can add React client and server via NuGet packages, and write react modules to insert on Razor pages, in which Babel will translate the React module into JavaScript and integrate into the server generated HTML and send the page to the client. So instead of client generating React JavaScript, it's done on the server side, so that .Net can keep track of it.
Babel is a translator, that can generate backwards compatible JavaScript from ECMAScript 2015+
What is Babel? · Babel
So in my mind from what I read of it, Blazer is sort of like ReactJS using Babel, or AngularJS in which you can create a single page application SPA within a single Razor page all in c# without the steep learning curve of ReactJS or AngularJS.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I have a GridView with template fields and one of the template field is a dropdownlist which is dynamically added into the gridview control. It's working properly on page load when I click the button control to the get the values from the template fields it will throw a null reference exception. Please correct my error, I am in pathetic situation. I attached the source code.
Regards
rites|Alert Moderators
asolmduasolmdu
None
0 Points
1 Post
gridview with dynamic dropdownlist control null exception
33 minutes ago|LINK|157.50.247.59
I have a GridView with template fields and one of the template field is a dropdownlist which is dynamically added into the gridview control. It's working properly on page load when I click the button control to the get the values from the template fields it will throw a null reference exception. Please correct my error, I am in pathetic situation. I attached the source code.
Regards
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
OnRowCreated="GridView1_RowCreated">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="id" runat="server" Text='<%# Eval("RGNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="name" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lastname" runat="server" Text='<%# Eval("DOB") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGridView();
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlResult = new DropDownList();
ddlResult.ID = "ddlResult";
ddlResult.Items.Insert(0, new ListItem("PASS", "0"));
ddlResult.Items.Insert(1, new ListItem("FAIL", "1"));
PlaceHolder p = (PlaceHolder)e.Row.FindControl("PlaceHolder1");
p.Controls.Add(ddlResult);
}
}
private void BindGridView()
{
GridView1.DataSource = CreateDataSource();
GridView1.DataBind();
}
public DataTable CreateDataSource()
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("RGNO", typeof(string)));
dt.Columns.Add(new DataColumn("NAME", typeof(string)));
dt.Columns.Add(new DataColumn("DOB", typeof(string)));
dr = dt.NewRow();
dr["RGNO"] = "1001";
dr["NAME"] = "PRAKASH";
dr["DOB"] = "10-10-2003";
dt.Rows.Add(dr);
return dt;
}
protected void Button1_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
DropDownList dd1 = (DropDownList)row.FindControl("ddlResult");
Response.Write(dd1.SelectedItem.Text);
}
}
|
|
|
|
|
i want to add video calling "one to one and one to many" function on my web page using asp.net bt i dont understand how i can add this on my web site
|
|
|
|
|
You can either buy something that supports what you want to do, or spend years writing millions of lines of code spanning many different technologies to achieve this.
|
|
|
|
|
|
This my aspx code
<table align="center">
<tr valign="top">
<td>
<asp:DataList ID="gv1" runat="server" RepeatColumns="1" RepeatDirection="Horizontal">
<HeaderTemplate>
Our Tutors List</HeaderTemplate>
<ItemTemplate>
<table width="600px" border="2" align="center">
<tr align="center">
<td width="100%" valign="top" style="font-size: 15px">
Name: <%#DataBinder.Eval(Container.DataItem, "FirstName")%> <%#DataBinder.Eval(Container.DataItem, "LastName")%>
<%--Mobile: <%#DataBinder.Eval(Container.DataItem, "MobileNo")%>
Email Id: <%#DataBinder.Eval(Container.DataItem, "EmailId")%> --%>
</td>
</tr>
<tr>
<td>
Qualification: <%#DataBinder.Eval(Container.DataItem, "Qualification")%>
Experience: <%#DataBinder.Eval(Container.DataItem, "Experience")%>
</td>
</tr>
<tr>
<td>
Subjects:
<%#DataBinder.Eval(Container.DataItem, "Subjects")%>
<%--Created Date: <%#DataBinder.Eval(Container.DataItem, "CreatedDate")%>--%>
</td>
</tr>
<tr>
<td>
Locations:
<%#DataBinder.Eval(Container.DataItem, "Location")%>
</td>
</tr>
<tr>
<td>
Description:
<%#DataBinder.Eval(Container.DataItem, "Description")%>
</td>
</tr>
</table><br /><br />
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:DataList>
<table width="100%" border="0">
<tr bgcolor="" align="center">
<td>
<asp:LinkButton ID="lnkbtnPrevious" runat="server" Text="<" OnClick="lnkbtnPrevious_Click"></asp:LinkButton>
</td>
<td>
<asp:DataList ID="dlPaging" runat="server" RepeatDirection="Horizontal" OnItemDataBound="dlPaging_ItemDataBound"
OnItemCommand="dlPaging_ItemCommand" OnSelectedIndexChanged="dlPaging_SelectedIndexChanged"
UseAccessibleHeader="True">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnPaging" runat="server" CommandArgument='<%#Eval("PageIndex")%>'
CommandName="lnkbtnPaging" Text='<%#Eval("PageText")%>'></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</td>
<td>
<asp:LinkButton ID="lnkbtnNext" runat="server" Text=">" OnClick="lnkbtnNext_Click"></asp:LinkButton>
</td>
</tr>
</table>
</td>
</tr>
</table>
<aspx.cs code="">
using System;
using System.Data;
using System.Web.UI.WebControls;
public partial class MathsTutors : System.Web.UI.Page
{
PagedDataSource pds = new PagedDataSource();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
ClsTutorDetails tutor = new ClsTutorDetails();
DataTable dt = tutor.GetAllTutors("Active");
pds.DataSource = dt.DefaultView;
pds.AllowPaging = true;
pds.PageSize = 12;
pds.CurrentPageIndex = CurrentPage;
lnkbtnNext.Enabled = !pds.IsLastPage;
lnkbtnPrevious.Enabled = !pds.IsFirstPage;
gv1.DataSource = pds;
gv1.DataBind();
if (dt.Rows.Count <= 12)
{
dlPaging.Visible = false;
lnkbtnNext.Visible = false;
lnkbtnPrevious.Visible = false;
}
else
{
dlPaging.Visible = true;
lnkbtnNext.Visible = true;
lnkbtnPrevious.Visible = true;
}
doPaging();
}
#region
private void doPaging()
{
DataTable dt = new DataTable();
dt.Columns.Add("PageIndex");
dt.Columns.Add("PageText");
for (int i = 0; i < pds.PageCount; i++)
{
DataRow dr = dt.NewRow();
dr[0] = i;
dr[1] = i + 1;
dt.Rows.Add(dr);
}
dlPaging.DataSource = dt;
dlPaging.DataBind();
}
public int CurrentPage
{
get
{
if (this.ViewState["CurrentPage"] == null)
return 0;
else
return Convert.ToInt16(this.ViewState["CurrentPage"].ToString());
}
set
{
this.ViewState["CurrentPage"] = value;
}
}
protected void lnkbtnPrevious_Click(object sender, EventArgs e)
{
CurrentPage -= 1;
BindData();
}
protected void lnkbtnNext_Click(object sender, EventArgs e)
{
CurrentPage += 1;
BindData();
}
protected void dlPaging_SelectedIndexChanged(object sender, EventArgs e)
{
CurrentPage = 0;
BindData();
}
protected void dlPaging_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName.Equals("lnkbtnPaging"))
{
CurrentPage = Convert.ToInt16(e.CommandArgument.ToString());
BindData();
}
}
protected void dlPaging_ItemDataBound(object sender, DataListItemEventArgs e)
{
LinkButton lnkbtnPage = (LinkButton)e.Item.FindControl("lnkbtnPaging");
if (lnkbtnPage.CommandArgument.ToString() == CurrentPage.ToString())
{
lnkbtnPage.Enabled = false;
lnkbtnPage.Font.Bold = true;
}
}
#endregion
}
|
|
|
|
|
|
Using VS2019 with Core 3 I am attempting to secure a web project. Web API does the validation and returns a JWT token with the user authorisation details, role only. Tihs works fine as the JWT decodes with all the correct info in it.
My problem is to get that information into MS Identity (or have I got it completely wrong).
I am NOT using EntityFrameworkCore just to service the user validation.
My login partial has the following.
@if (User.Identity.IsAuthenticated)
{
<form asp-controller="Account" asp-action="Logout" method="post" id="logoutForm">
<ul>
<li>
<button type="submit">Log out</button>
</li>
</ul>
</form>
}
else
{
<ul>
<li><a asp-page="/Login">Log in</a></li>
</ul>
}
The .cs code
public async Task<IActionResult> OnPostAsync(string returnUrl = null)
{
CSDUtil.PWDUtil oUtil = new CSDUtil.PWDUtil();
try
{
ReturnUrl = returnUrl;
if (ModelState.IsValid)
{
UserDetailsDB data = UserDetails;
UserDetailsDB oUser = await dsUserDetails.AutenticateAsync(data);
if (oUser == null)
{
ModelState.AddModelError(string.Empty, "Invalid user details.");
return Page();
}
JwtSecurityTokenHandler oHandler = new JwtSecurityTokenHandler();
var key = Code.MainUI.Key;
var handler = new JwtSecurityTokenHandler();
var jwtToken = new JwtSecurityToken(oUser.Token);
var validations = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey = new SymmetricSecurityKey(key),
ValidateIssuer = false,
ValidateAudience = false
};
ClaimsPrincipal oPrincipal = handler.ValidateToken(oUser.Token, validations, out SecurityToken oToken);
int i = oPrincipal.Claims.Count();
var authProperties = new AuthenticationProperties
{
AllowRefresh = true,
ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(60),
IsPersistent = true,
IssuedUtc = DateTimeOffset.Now,
RedirectUri = "/Index"
};
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
new ClaimsPrincipal(oPrincipal),
authProperties);
var B = User.Identity.IsAuthenticated;
return LocalRedirect(Url.GetLocalUrl(returnUrl));
}
}
The ClaimsPricipal populates correctly with the details of the user in identities[0] of that collection.
How do I move the user details from the ClaimsPrincipal to the User.Identity?
[Edit]
I have the claims added to User.Identity but IsAuthenticated is still false
ClaimsPrincipal oPrincipal = handler.ValidateToken(oUser.Token, validations, out SecurityToken oToken);
returnUrl = "/Index";
ClaimsIdentity identity = User.Identity as ClaimsIdentity;
foreach (Claim oClaim in oPrincipal.Claims)
{
identity.AddClaim(oClaim);
}
var B = User.Identity.IsAuthenticated;
return LocalRedirect(Url.GetLocalUrl(returnUrl));
[/Edit]
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
modified 28-Oct-19 19:42pm.
|
|
|
|
|
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)
{
String[] newRoles = { "Administrator" };
GenericIdentity newIdentity = new GenericIdentity(pResult.AccountName);
GenericPrincipal newPrincipal = new GenericPrincipal(newIdentity, newRoles);
httpContext.User = newPrincipal;
System.Threading.Thread.CurrentPrincipal = httpContext.User;
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
|
|
|
|
|
Now that feels like a hack
Does JWT not allow you to recycle the credentials via the server by passing them back and forth in the token?
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
JWT just generates a unique token, that contains information about the user, and some other parameters such as length of authorized time, and expiration date. So with a token, you can store it in the browsers Local Storage using JavaScript and read it back it using JavaScript. With JavaScript you can get info out of the token, or check to see if the token is expired, and then refresh it or issue a new one.
In Angular, you pickup the token, and pass the token in the header sent to the .Net Core V2.2+ API.
headers: new HttpHeaders({
"Content-Type": "application/json",
"Accept": "application/json",
"Authorization": "Bearer " + tokenGetter
})
And then the API will run a service or something called Authorize.
[HttpGet("GetAdminBrands/{page}/{show}"), Authorize]
public async Task<GetBrands> GetAdminBrands(int page, int show)
{
var brand = await _brandsRepository.GetBrands(page, show);
return brand;
}
You set this up in Startup
services.AddAuthorization(auth =>
{
auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
.RequireAuthenticatedUser().Build());
});
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
var settings = Configuration.GetSection("Settings");
var secretKey = settings.GetValue<string>("Auth0:Secret");
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(secretKey));
var authority = settings.GetValue<string>("Auth0:Authority");
var audience = settings.GetValue<string>("Auth0:Audience");
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidIssuer = authority,
ValidAudience = audience,
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(secretKey))
};
});
So above is what I'm using now, which is Angular wrapped in .Net Core V2.2+
The code I posted earlier was a work around or hack to avoid using Microsoft.Identity in it's full scale, since I just wanted a partial portion of it. What I mean by full scale was having to use such a large chunk of controllers, models and views in which no explanation was really provided in how it works and why. Microsoft.Identity was take it or leave it with nothing in between. That prompted me to do some reverse engineering of it to see how it worked, and hack something else together that was more light weight.
When I think about it now, JWT pretty much works the same way as my hack does. But there's a large JavaScript client side library to support it, and is not all server side.
I did post questions about my hack 3 years ago and nobody bashed it. But I did hear crickets about it as to nobody here posted a single comment about it.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|