-
Notifications
You must be signed in to change notification settings - Fork 0
/
Notes.txt
114 lines (82 loc) · 3.85 KB
/
Notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
ASP.NET Core web API documentation with Swagger / OpenAPI
- Install Swashbuckle.Aspnetcore
1.Right-click the API project in Solution Explorer and select Manage NuGet Packages
2.Type Swashbuckle.AspNetCore in the search box
3.Select Swashbuckle.AspNetCore and click Install
- Configure Swagger Middleware
services.AddSwaggerGen();
- Configure
// This middleware serves generated Swagger document as a JSON endpoint
app.UseSwagger();
// This middleware serves the Swagger documentation UI
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Employee API V1");
});
URL for document: https://localhost:44379/swagger/index.html
https://localhost:44379/swagger/v1/swagger.json
-----------------------------------------------------------------------
In Program.cs, we add following code
.ConfigureLogging(logBuilder =>
{
logBuilder.ClearProviders(); // removes all providers from LoggerFactory
logBuilder.AddConsole();
logBuilder.AddTraceSource("Information, ActivityTracing"); // Add Trace listener provider
})
2. add code in startup.cs with methodd Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
// other code remove for clarity
loggerFactory.AddFile("Logs/mylog-{Date}.txt");
}
3. install package through PackageManager console
Install-Package Serilog.Extensions.Logging.File -Version 2.0.0
---------------
wwwroot
- wwwroot folder in the ASP.NET Core project is treated as a web root folder
- Static files can be stored in any folder under the web root and accessed with a relative path to that root
#### add bootstrap and jquery file
-> wwwroot -> right click -> add file - Client-side Libarary
- right click on libman.json file and select "Restore Client-Side Libraries" from the context menu
-----------------------
JWTToken - https://jwt.io/introduction
Step 1 :- Generate
- `public string GenerateJSONWebToken()
{
// when he is validated AD
var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256);
var claims = new[] {
new Claim(JwtRegisteredClaimNames.Sub, "sar"),
new Claim(JwtRegisteredClaimNames.Email, "sarveshmcasoft@gmail.com"),
new Claim("Role", "Admin"),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
};
var token = new JwtSecurityToken(_config["Jwt:Issuer"],
_config["Jwt:Issuer"],
claims,
expires: DateTime.Now.AddMinutes(120),
signingCredentials: credentials);
return new JwtSecurityTokenHandler().WriteToken(token);
}`
Step 2: Attache the middle ware
` services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuerSigningKey = true,
ValidIssuer = Configuration["Jwt:Issuer"],
ValidAudience = Configuration["Jwt:Issuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"]))
};
});`
Step 3: Add data in file appsettings.json
`"Jwt": {
"Key": "545454568686869898989",
"Issuer": "sarveshsoft"
}`