how to redirect UI application to access denied on every type of request in .net core

57 views
Skip to first unread message

dharmesh art channel

unread,
Aug 14, 2020, 1:41:21 PM8/14/20
to RestSharp

I have two application one is API and one is UI, in api some methods or permission based return as per below code

if (!await _permissionMasterServcie.Authorize(StandardPermissionProvider.Category, PermissionType.View).ConfigureAwait(false)) { return AccessDenied(); }

then this consume in UI .net core application. In this application some method is call by jQuery or Kendoui grid, some MVC so when UI .net core application consume API its got status code "401 Unauthorized" so can we redirect every request in UI application to access denied page when status code received "401 Unauthorized". By any attribute or any configuration in startup file. I didn't get how to do that.

UI .net core application consuming api

public virtual async Task<IRestResponse> PostAsync(string request, string endPoint, string action, string token) { string url = endPoint + action; _restClient.BaseUrl = new Uri(url); _restRequest.Method = Method.POST; _restRequest.Timeout = 900000; _restRequest.Parameters.Clear(); _restRequest.AddHeader("Authorization", token); _restRequest.AddParameter("application/json", request, ParameterType.RequestBody); IRestResponse response = await _restClient.ExecuteAsync(_restRequest, Method.POST); return response; }

here I'm getting response and status code both, here can we redirect every request to access denied for 401 code

Alexey Zimarev

unread,
Aug 16, 2020, 4:42:29 AM8/16/20
to RestSharp
It has nothing to do with RestSharp, I guess you need to read more about using redirects in ASP.NET controllers and how it handles authorisation.
Reply all
Reply to author
Forward
0 new messages