本文介绍了基于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的自定义授权
发布评论