Local主机在重定向到特定URL的同时,将您重定向多次
我创建了一个操作过滤器来检查一些语句,然后将客户端重定向到特定的操作或路由,但是当我运行应用程序浏览器时,请显示此页面: page image
我的代码:
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
var customer = await _workContext.GetCurrentCustomerAsync();
var vendor = _vendorRepository.GetAll()
.FirstOrDefault(w => w.CustomerId == customer.VendorId);
if (vendor == null)
return;
if (!(vendor.ActivationDate < DateTime.Now))
return;
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("action", "CheckVendorDate");
redirectTargetDictionary.Add("controller", "VendorActivation");
context.Result=new RedirectToRouteResult(redirectTargetDictionary);
}
update update :
如果您想检查操作和Controler名称在OnaThorizationAsync方法中,以防止引起递归重定向或等等,请使用此代码:
var descriptor = context?.ActionDescriptor as ControllerActionDescriptor;
var action = descriptor.ActionName;
var controllerName = descriptor.ControllerName;
I created an action filter to check some statements then redirect client to specific action or route, but when I run the application browser shows this page:
Page Image
My code:
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
var customer = await _workContext.GetCurrentCustomerAsync();
var vendor = _vendorRepository.GetAll()
.FirstOrDefault(w => w.CustomerId == customer.VendorId);
if (vendor == null)
return;
if (!(vendor.ActivationDate < DateTime.Now))
return;
RouteValueDictionary redirectTargetDictionary = new RouteValueDictionary();
redirectTargetDictionary.Add("action", "CheckVendorDate");
redirectTargetDictionary.Add("controller", "VendorActivation");
context.Result=new RedirectToRouteResult(redirectTargetDictionary);
}
Update :
If you want to check action and controller name in OnAuthorizationAsync method , to prevent causing recursive redirection or etc , use this code :
var descriptor = context?.ActionDescriptor as ControllerActionDescriptor;
var action = descriptor.ActionName;
var controllerName = descriptor.ControllerName;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎是在引起递归重定向,需要进行额外检查以防止重定向
/vendoractivation/checkvendordate
如果上下文来自该路线。You seem to be causing recursive redirection, an additional check is needed to prevent redirection to
/VendorActivation/CheckVendorDate
if context is from that route.