【问题标题】:isAuthenticated not recognized on rewritten pagesisAuthenticated 在重写页面上无法识别
【发布时间】:2023-03-14 20:58:01
【问题描述】:

我在我的网站上使用 UrlRewriting 模块,但我似乎无法让 HttpContext.Current.Request.IsAuthenticated 在任何重写的页面上返回“true”。

如果我去我的主页 (http://localhost/default.aspx) 我会得到“真”,但如果我去类似的东西 (http://localhost/contactus) 我总是会得到“假”。

为什么会这样?

另外,举一个直接的例子,我有一个编辑栏,应该对任何经过身份验证的人显示。在 Page_Load 方法中触发 if 语句

If HttpContext.Current.Request.IsAuthenticated Then _ 
Me.FindControl("EditBar").Visible = True

我也试过把它放在页面加载事件中

Response.Write(HttpContext.Current.Request.IsAuthenticated.ToString)

每一个被重写的页面都说“False”,而没有被重写的页面说“True”。

【问题讨论】:

    标签: asp.net asp.net-membership url-rewriting


    【解决方案1】:

    我有一个similar issue。将以下内容添加到您的 web.config 是否可以解决您的问题?

    <modules runAllManagedModulesForAllRequests="true">
    

    【讨论】:

    • 很遗憾,没有,我从一开始就一直这样做。
    【解决方案2】:

    嗯,我的问题中的代码不起作用,那么这段代码就起作用了。

    User.Identity.IsAuthenticated
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多