Custom authorization based on url in ASP.NET MVC

只谈情不闲聊 提交于 2019-12-13 06:07:44

问题


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);

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.


回答1:


Remove the virtual path before checking it:

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

Works both for virtual dirs and domains.



来源:https://stackoverflow.com/questions/17844922/custom-authorization-based-on-url-in-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!