子域问题

发布于 2024-07-24 18:03:35 字数 772 浏览 3 评论 0原文

基本概述...

我在 iis 中有一个站点设置...
- “mysite”(wwwroot\mysite) 下有 2 个虚拟目录应用程序
- “上传”(\uploadfiles)
-“app”(wwwroot\myapp)

我还有一个子域,在 iis 中设置为不同的站点...
- “beta.mysite”(wwwroot\mysitebeta)下有2个虚拟目录
- “上传”(\uploadfiles)
-“app”(wwwroot\myappbeta)

子域工作正常....我可以输入 https:/ /beta.mysite.com/app ...它使测试站点登录完全正常...问题是,当我单击任何创建回发的按钮时...它恢复到 https://www.mysite.com/app...

所有链接都显示他们的文件的正确相对路径...如果我输入 https:// beta.mysite.com/app/dir/page.aspx...它实际上会转到测试版网站上的该页面,所有链接都会转到正确的位置...这只是回发杀了我……

basic overview...

i have a site setup in iis...
- "mysite" (wwwroot\mysite) under that there are 2 virtual directory applications
- "uploads" (\uploadfiles)
- "app" (wwwroot\myapp)

I also have a subdomain that is set up as a different site in iis...
- "beta.mysite" (wwwroot\mysitebeta) under that there are 2 virtual directory
- "uploads" (\uploadfiles)
- "app" (wwwroot\myappbeta)

the sub domain is working fine.... i can type in https://beta.mysite.com/app ... and it brings up the beta site log in perfectly fine.... the problem is, when i click on any of the buttons that create a post back... it reverts to https://www.mysite.com/app...

all of the links display the correct relative path to their files.... and if i type in https://beta.mysite.com/app/dir/page.aspx... it will actually go to that page on the beta site, all the links are going to the right spots... its just the postbacks that are killing me...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

极度宠爱 2024-07-31 18:03:36

您是否尝试过为这两个网站设置不同的应用程序池? 看起来它试图变得“聪明”,并得出结论:这两个虚拟目录实际上是同一个网站。

如果所有其他方法都失败,您可以重写 ASP.NET 手动生成的 FORM 标记中的回发 URL。 使用 App_Browsers 文件和 ControlAdapter 可能是最简洁的方法。

我有一个这样的 ControlAdapter 实现的示例,尽管它旨在与 URL 重写一起使用,以防止在回发时恢复到实际的幕后 URL。 但是,我认为它可以解决您的开箱即用的

public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter 
{
    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(new RewriteFormHtmlTextWriter(writer));
    }
}

public class RewriteFormHtmlTextWriter : HtmlTextWriter
{
    private const string contextItemKey = "FormActionWritten";

    public RewriteFormHtmlTextWriter(HtmlTextWriter writer) : base(writer)
    {
        InnerWriter = writer.InnerWriter;
    }

    public RewriteFormHtmlTextWriter(System.IO.TextWriter writer) : base(writer)
    {
        base.InnerWriter = writer;
    }

    public override void WriteAttribute(string name, string value, bool fEncode)
    {
        // If the attribute we are writing is the "action" attribute, and we are not on a sub-control, 
        // then replace the value to write with the raw URL of the request - which ensures that we'll
        // preserve the PathInfo value on postback scenarios

        if (name == "action" && !HttpContext.Current.Items.Contains(contextItemKey))
        {
            // Use the Request.RawUrl property to retrieve the un-rewritten URL
            value = HttpContext.Current.Request.RawUrl;
            HttpContext.Current.Items[contextItemKey] = true;
        }

        base.WriteAttribute(name, value, fEncode);
    }
}

Form.browser 文件问题:

<browsers>
    <browser refID="Default">
        <controlAdapters>
            <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="FormRewriterControlAdapter" />
        </controlAdapters>
    </browser>
</browsers>

Have you tried setting a different application pool for these two websites? Looks like it's trying to be "smart" and concludes that the two virtual directories are actually the same website.

If all else fails, you could rewrite the postback URL in the FORM-tag that ASP.NET generates manually. Using an App_Browsers file and a ControlAdapter are probably the cleanest way of doing that.

I have an example of such a ControlAdapter implementation, though it is intended to work with URL rewriting to prevent reverting to the actual behind-the-scenes URL on postback. However, I think it would work for your problem out-of-the-box

public class FormRewriterControlAdapter : System.Web.UI.Adapters.ControlAdapter 
{
    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(new RewriteFormHtmlTextWriter(writer));
    }
}

public class RewriteFormHtmlTextWriter : HtmlTextWriter
{
    private const string contextItemKey = "FormActionWritten";

    public RewriteFormHtmlTextWriter(HtmlTextWriter writer) : base(writer)
    {
        InnerWriter = writer.InnerWriter;
    }

    public RewriteFormHtmlTextWriter(System.IO.TextWriter writer) : base(writer)
    {
        base.InnerWriter = writer;
    }

    public override void WriteAttribute(string name, string value, bool fEncode)
    {
        // If the attribute we are writing is the "action" attribute, and we are not on a sub-control, 
        // then replace the value to write with the raw URL of the request - which ensures that we'll
        // preserve the PathInfo value on postback scenarios

        if (name == "action" && !HttpContext.Current.Items.Contains(contextItemKey))
        {
            // Use the Request.RawUrl property to retrieve the un-rewritten URL
            value = HttpContext.Current.Request.RawUrl;
            HttpContext.Current.Items[contextItemKey] = true;
        }

        base.WriteAttribute(name, value, fEncode);
    }
}

Form.browser file:

<browsers>
    <browser refID="Default">
        <controlAdapters>
            <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="FormRewriterControlAdapter" />
        </controlAdapters>
    </browser>
</browsers>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文