【问题标题】:IIS7 redirect between virtual dirsIIS7 在虚拟目录之间重定向
【发布时间】:2011-04-21 09:58:27
【问题描述】:

在我们的 asp.net 应用程序中,我们有几个虚拟目录。在 IIS7 中,这些被称为“应用程序”,它们都具有相同的应用程序池,以经典管道模式运行。

  • www.webapp.com/example1
  • www.webapp.com/example2

它们都指向同一个物理目录,例如 C:\webapp。唯一的区别是它们每个都有一个底层虚拟目录,指向不同的 CSS 文件夹,该文件夹位于 C:\webapp\styles\ 中(例如 C:\webapp\styles\example1\base.css 等)

我们使用表单身份验证和内置的成员资格提供程序。我们遇到的问题是这样的:

当用户浏览 www.webapp.com/example1/page.aspx 并单击重定向到 www.webapp.com/example2/otherpage.aspx 的链接时,用户会被重定向到 www.webapp.com /example2/login.aspx。会话好像过期了。

我们真的不知道在哪里寻找解决方案,非常感谢任何指针! 提前致谢! 斯蒂金

【问题讨论】:

    标签: asp.net session iis-7 virtual-directory


    【解决方案1】:

    我们找到了解决方案,所以我想与 SO 社区分享:

    通过反射将 AppDomainAppId 设置为固定值(在本例中为 applicationName):

    Globals.asax.cs:

        protected void Application_Start(object sender, EventArgs e)
        {
            // make sure all set the same AppDomainAppId
            FieldInfo runtimeInfo = typeof(HttpRuntime).GetField("_theRuntime", BindingFlags.Static | BindingFlags.NonPublic);
            if (runtimeInfo == null) return;
            HttpRuntime theRuntime = (HttpRuntime)runtimeInfo.GetValue(null);
            if (theRuntime == null) return;
            FieldInfo appNameInfo = typeof(HttpRuntime).GetField("_appDomainAppId", BindingFlags.Instance | BindingFlags.NonPublic);
            if (appNameInfo == null) return;
            var appName = (String)appNameInfo.GetValue(theRuntime);
            if (appName != "applicationName") appNameInfo.SetValue(theRuntime, "applicationName");
        }
    

    【讨论】:

      猜你喜欢
      • 2013-07-30
      • 2010-11-17
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-19
      • 2011-02-12
      • 2011-12-15
      • 2011-09-19
      相关资源
      最近更新 更多