16,022,971 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Visual Basic questions
View Javascript questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by A Belal (Top 14 by date)
A Belal
19-Dec-23 13:01pm
View
Deleted
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.ValidateKeyPropertiesAndExtractCancellationToken(Object[] keyValues, Boolean async, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.FindAsync(Object[] keyValues, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.FindAsync(Object[] keyValues)
at BL.Repositories.BaseRepository`1.<getbyidasync>d__3.MoveNext() in E:\Programming\على folder\SoqRepository\BL\Repositories\BaseRepository.cs:line 53
A Belal
19-Dec-23 12:54pm
View
Notice
when i do breakPoint
and stop in every Line
the Code in this Line is appear as below
{
return LapShopContext.Set<t>().Find(id);
id = 0x00000094
}
A Belal
19-Dec-23 8:45am
View
i make abreakPoint
and debug code
and Error in this Line below
public T GetById(int? id)
{
try
{
if (id.HasValue)
{
Error in this Line below
this :
return LapShopContext.Set<t>().Find(id.Value);
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.ValidateKeyPropertiesAndExtractCancellationToken(Object[] keyValues, Boolean async, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.Find(Object[] keyValues)
at BL.Repositories.BaseRepository`1.GetById(Nullable`1 id) in E:\Programming\على شاهين كورس\SoqRepository\BL\Repositories\BaseRepository.cs:line 53
}
else
{
return null;
}
}
catch (Exception)
{
return null;
}
}
A Belal
18-Dec-23 16:47pm
View
i tried your code
and Error Here
public T GetById(int? id)
{
try
{
return LapShopContext.Set<t>().Find(id); => this Line
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.ValidateKeyPropertiesAndExtractCancellationToken(Object[] keyValues, Boolean async, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Internal.EntityFinder`1.Find(Object[] keyValues)
at BL.Repositories.BaseRepository`1.GetById(Nullable`1 id) in E:\Programming\Folder\SoqRepository\BL\Repositories\BaseRepository.cs:line 51
}
catch (Exception)
{
return null;
}
}
A Belal
18-Dec-23 16:28pm
View
the same error
and
Notice
when i do breakPoint
and stop in every Line
the Code in this Line is appear as below
{
return LapShopContext.Set<t>().Find(id);
id = 0x00000094
}
in address bar https://localhost:7201/admin/item/Delete?ItemId=19
my page is
This page isn’t workingIf the problem continues, contact the site owner.
HTTP ERROR 400
A Belal
21-Nov-23 11:28am
View
Controller named Values
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ValuesController : ControllerBase
{
// GET: api/<valuescontroller>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<valuescontroller>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<valuescontroller>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<valuescontroller>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<valuescontroller>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
Controller named login
[Route("api/[controller]")]
[ApiController]
public class loginController : ControllerBase
{
IConfiguration configuration;
public loginController(IConfiguration configuration)
{
this.configuration = configuration;
}
// GET: api/<login>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<login>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<login>
[HttpPost]
[AllowAnonymous]
public IActionResult Post([FromBody] UserModel model)
{
try
{
var response = Unauthorized();
UserModel myuser = Authorize(model);
if (myuser != null)
{
var token = GenerateToken(model);
return Ok(new{token=token});
}
return response;
}
catch (Exception ex)
{
throw ex;
}
}
public string GenerateToken(UserModel user)
{
var SecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JWT:Key"]));
var credentials = new SigningCredentials(SecurityKey, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(configuration["JWT:Issuer"],
configuration["JWT:Key"], null,
expires: DateTime.Now.AddMinutes(2000),
signingCredentials: credentials);
return new JwtSecurityTokenHandler().WriteToken(token);
}
public UserModel Authorize(UserModel model)
{
try
{
if (model.UserName == "ah" && model.Password == "123")
{
return new UserModel
{
UserName = "ah",
Email = "ab5221744@gmail.com"
};
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
// PUT api/<login>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<login>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
do you have any Notes
A Belal
21-Nov-23 11:27am
View
Controller named Values
[Route("api/[controller]")]
[ApiController]
[Authorize]
public class ValuesController : ControllerBase
{
// GET: api/<valuescontroller>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<valuescontroller>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<valuescontroller>
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/<valuescontroller>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<valuescontroller>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
Controller named login
[Route("api/[controller]")]
[ApiController]
public class loginController : ControllerBase
{
IConfiguration configuration;
public loginController(IConfiguration configuration)
{
this.configuration = configuration;
}
// GET: api/<login>
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/<login>/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/<login>
[HttpPost]
[AllowAnonymous]
public IActionResult Post([FromBody] UserModel model)
{
try
{
var response = Unauthorized();
UserModel myuser = Authorize(model);
if (myuser != null)
{
var token = GenerateToken(model);
return Ok(new{token=token});
}
return response;
}
catch (Exception ex)
{
throw ex;
}
}
public string GenerateToken(UserModel user)
{
var SecurityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["JWT:Key"]));
var credentials = new SigningCredentials(SecurityKey, SecurityAlgorithms.HmacSha256);
var token = new JwtSecurityToken(configuration["JWT:Issuer"],
configuration["JWT:Key"], null,
expires: DateTime.Now.AddMinutes(2000),
signingCredentials: credentials);
return new JwtSecurityTokenHandler().WriteToken(token);
}
public UserModel Authorize(UserModel model)
{
try
{
if (model.UserName == "ah" && model.Password == "123")
{
return new UserModel
{
UserName = "ah",
Email = "ab5221744@gmail.com"
};
}
return null;
}
catch (Exception ex)
{
throw ex;
}
}
// PUT api/<login>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<login>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
do you have any Notes
A Belal
21-Nov-23 11:21am
View
i do that now new Error is
Online
02:48:44.055
GET https://localhost:7107/api/values
Error: connect ECONNREFUSED 127.0.0.1:7107
Request Headers
User-Agent: PostmanRuntime/7.35.0
Accept: */*
Postman-Token: f73459b3-a3ed-43bb-91c9-929a082bd90f
Host: localhost:7107
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
02:48:51.097
POST https://localhost:7107/api/login
Error: connect ECONNREFUSED 127.0.0.1:7107
Request Headers
Content-Type: application/json
User-Agent: PostmanRuntime/7.35.0
Accept: */*
Postman-Token: f64c27f0-331a-44d1-a5cf-d6512aff23d4
Host: localhost:7107
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
A Belal
21-Nov-23 11:15am
View
Richard Deeming, That's my Class Program.cs
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.Tokens;
using System.Text;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(o =>
{
o.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
{
ValidIssuer = builder.Configuration["JWT:Issuer"],
ValidAudience = builder.Configuration["JWT:Audience"],
IssuerSigningKey=new SymmetricSecurityKey
(Encoding.UTF8.GetBytes(builder.Configuration["JWT:Key"])),
ValidateIssuer=true,
ValidateAudience=true,
ValidateLifetime=true,
ValidateIssuerSigningKey=true
};
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}")
.RequireAuthorization();
app.Run();
A Belal
20-Nov-23 14:21pm
View
ok my best friend i will tell you , i get tokenKey from path https://localhost:7107/api/login And when i try to test token and get data from Path https://localhost:7107/api/Values
the token key work good and data comes well
but when i remove token the data continue come and didn't tell me that iam UnAuthorized
i want if i remove token from Postman the didn't come because Iam UnAuthorized
i mean when i remove token key from postman
i can't call data because i am not authorized
and infact that doesn't happen
i want to get token key from
path https://localhost:7107/api/login And when i try to test token and get data from Path https://localhost:7107/api/Values
in if i remove token key i Can't call data because iam not authorized
A Belal
12-Nov-23 14:20pm
View
Ok Eng-Richard MacCutchan Can you help me
A Belal
30-Oct-23 11:55am
View
Deleted
my view again @model CategoryFormViewModel
@{ViewData["Title"]=$"{(Model?.Id>0 ? "Edit" : "AddNew")} Category";}
Form elements
Forms
Form elements
Default form
Basic form layout
@if (Model?.Id > 0)
{
}
@ResAdmin.lblCategoryName
@ResAdmin.lblImage
@ResGeneral.lblSave
@ResGeneral.lblNew
@if (Model != null && Model.ImageName != null)
{
}
@section Scripts
{
var Upload = {
UploadDefaultImg: function(e) {
const file = e.target.files[0];
const reader = new FileReader();
reader.onloadend = () => {
CourseMediaImgName = file.name;
CourseMediaImgBase64 = reader.result.slice(reader.result.indexOf('base64,') + 7);
$("#tbImgName").html(file.name)
$("#tbImgSrc").html(`<img class="thumbnail" src = "${reader.result}" style = "width: 200px;height: 300px;border-radius: 5px;border: 1px solid #d9d9d9;padding: 1px;" />`)
};
reader.readAsDataURL(file);
}
}
}
A Belal
8-Jul-23 10:20am
View
of course i do backup
A Belal
17-Mar-23 12:33pm
View
thanks more OriginalGriff , i need to return All Data and i need to learn how
Show More