开发者

IIS7 redirect between virtual dirs

开发者 https://www.devze.com 2023-02-28 01:03 出处:网络
in our asp.net app, we have several virtual directories. In IIS7, these are called \"applications\" and they all have the same application pool, running in classic pipeline mode.

in our asp.net app, we have several virtual directories. In IIS7, these are called "applications" and they all have the same application pool, running in classic pipeline mode.

They all point to the same physical directory, say C:\webapp. The only difference is they each have an underlying virtual dir that points to a different CSS folder, which is located in C:\webapp\styles\ (eg. C:\webapp\styles\example1\base.css, etc)

We use forms authentication and the built-in membership provider. The problem we have is this:

When a user is browsing www.webapp.com/example1/page.aspx and clicks on a link that redirects to www.webapp.com/example2/otherpage.aspx,the user is instead redirected to www.webapp.com/example2/login.aspx. It seems as if the session expired.

We don't really know where to look for a solution, any pointers are greatly appreciated! Thanks in advance! Stijn


We found the solution so I thought I'd share this with the SO community:

set AppDomainAppId to a fixed value (in this case applicationName) through reflection:

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");
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号