TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ahmed elbarbary
NA
1.6k
275.3k
When Success Valid Access Token Not Return Result on next ?
Sep 13 2019 8:22 PM
I validate token using middle ware in asp.net core 2.2 in case of access token not valid return message not valid and this case work perfect
problem come when valid token success the problem is next request no give me result of action executed so that what i do for that working
problem is when success valid token is OK it reach until next but not display after that action that have result
in both cases if valid token or not valid return invalid token message .
public
async Task InvokeAsync(HttpContext context, DataContext dataContext)
{
var validKey =
false
;
// than you logic to validate token
var CheckExistAccessToken = context.Request.Headers.ContainsKey(
"Authorization"
);
var AccessTokenValue = context.Request.Headers[
"Authorization"
].SingleOrDefault();
//var token = AccessTokenValue.Substring(AccessTokenValue.IndexOf(' ') + 1);
if
(CheckExistAccessToken)
{
bool
isvalid = _tockenvalidator.ValidateToken(AccessTokenValue);
if
(isvalid)
{
validKey =
true
;
}
else
{
validKey =
false
;
}
}
if
(!validKey)
{
context.Response.StatusCode = (
int
)HttpStatusCode.Forbidden;
await context.Response.WriteAsync(
"Invalid Token"
);
}
//if valid than next middleware Invoke
else
{
await _next.Invoke(context);
// not return to me action i write on postman and return also message not valid token
}
}
}
public
static
class
TokenExtensions
{
public
static
IApplicationBuilder UseTokenAuth(
this
IApplicationBuilder builder)
{
return
builder.UseMiddleware
();
}
}
on configure of startup.cs
if
(env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// 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.UseTokenAuth();
app.UseHttpsRedirection();
app.UseStatusCodePagesWithReExecute(
"/error/{0}"
);
app.UseMvc();
app.UseCors(
"CorsData"
);
Reply
Answers (
2
)
Faulting module name: msvcrt.dll, version: 7.0.17763.475, ti
use of viewstate