基于ASP.NET MVC中的URL的自定义授权

编程入门 行业动态 更新时间:2024-10-25 09:32:35
本文介绍了基于ASP.NET MVC中的URL的自定义授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我将网址保存在数据库中,并且各个用户都映射到了该网址

I am saving url's in database and respective users are mapped to the url

URL: ~/user

从应用程序中,我正在通过

From application, I am checking via

bool isAuthorized = DBHelper.IsAuthorized( string.Concat("~" , Url.Action("Index", "User"), httpContext.User.Identity.Name);

在开发环境中效果很好.但是在生产中,应用程序是在IIS应用程序 ucms 下配置的,因此Url.Action("Index","User")返回/ucms/user,因此isAuthorized返回false.

It works well in development environment. But in production, application is configured under a IIS application ucms, so Url.Action("Index", "User") is returning /ucms/user henceisAuthorized is returning false.

任何人都可以提供任何输入或指导来应对要改变的行为.

Could anyone provide any inputs or direction on the changes to be done to tackle this behaviour.

推荐答案

在检查虚拟路径之前将其删除:

Remove the virtual path before checking it:

var relativePath = yourPath.Remove(0, HttpContext.Current.Request.ApplicationPath.Length);

适用于虚拟目录和域.

更多推荐

基于ASP.NET MVC中的URL的自定义授权

本文发布于:2023-11-14 10:29:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   NET   ASP   URL   MVC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!