【问题标题】:Custom authorization based on url in ASP.NET MVCASP.NET MVC中基于url的自定义授权
【发布时间】:2013-07-24 13:45:10
【问题描述】:

我正在将 url 保存在数据库中,并且相应的用户被映射到 url

URL: ~/user

从应用程序,我正在检查通过

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

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

任何人都可以提供任何意见或方向来解决这种行为。

【问题讨论】:

标签: c# asp.net-mvc asp.net-mvc-4 iis-7


【解决方案1】:

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

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

适用于虚拟目录和域。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-22
    • 2010-11-01
    • 2013-12-14
    • 2013-10-31
    • 2010-09-30
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多