在与母版页不同的文件夹中显示 aspx 页面时出现问题

发布于 2024-11-15 07:40:30 字数 136 浏览 2 评论 0原文

我有一个使用一些 JQuery 脚本的网站母版页,当我的网站访问我的帐户文件夹中的任何内容时,页面会加载,但并非没有错误消息以及混乱的母版页。如果我从“帐户”文件夹中拉出该页面,则效果很好。尝试了一整天来解决这个问题,但没有成功。感谢所提供的任何帮助。谢谢!

I have a site master page which uses some JQuery scripts, when my site accesses anything that is in my Account folder, the page loads but not without an error message as well as a messed up master page. It works fine if I pull the page out from the Account folder. Trying the entire day to figure this out but to no avail. Appreciate any help given. Thanks!

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

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

发布评论

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

评论(6

来日方长 2024-11-22 07:40:30

这与 CSS 和 JavaScript 的链接有关。确保添加“../”以提升文件夹结构的级别。

It'll be to do with your links to CSS and JavaScript. Ensure your add "../" to go up a level in folder structure.

一袭水袖舞倾城 2024-11-22 07:40:30

我认为可能存在安全问题

首先确保您在文件中添加了 javascript 文件的正确真实路径...

阅读以下内容: 为特定页面或文件夹设置授权规则web.config

允许匿名用户访问 Account.aspx 页面。
复制

<configuration>
   <location path="~/Users>
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>

I think there may be security issue

First ensure that you added proper realtive path of the javascript file in you file...

and

Read this : Setting authorization rules for a particular page or folder in web.config

allow an anonymous user to gain access the Account.aspx page.
Copy

<configuration>
   <location path="~/Users>
      <system.web>
         <authorization>
            <allow users="?"/>
         </authorization>
      </system.web>
   </location>
</configuration>
静待花开 2024-11-22 07:40:30

我们确实没有足够的信息来提供明确的答案 - 例如,“错误消息”是什么意思?来源是什么?它是如何显示的?最重要的是,它说了什么?如果删除 jQuery 的使用,页面会按预期显示和运行吗?

除此之外,为了解决“混乱的 MasterPage”问题,我假设您的帐户文件夹通过 web.config 的 authorization 部分进行了限制访问。可以对此进行调整以允许访问某些资源;在 authorization 部分,您可能会看到类似这样的内容:

<authorization>
    <deny users="?"/>
    <allow users="*"/>
</authorization>

上面的内容将锁定对其范围内的路径内的所有文件的访问。当然,您的登录页面将可以访问,但可能无法访问 CSS 文件和图像等资源 - 为了允许尚未经过身份验证的用户访问这些资源,您可以配置自定义位置,如下所示:

<location path="pathToResources">
    <system.web>
        <authorization>
            <allow users="?"/>
        </authorization>
    </system.web>
</location>

We don't really have sufficient information to provide a definitive answer here - for instance, what do you mean by 'an error message'? What is the source? How is it displayed? and, most importantly, what does it say? What happens if you remove use of jQuery, does the page display and function as expected?

That aside, to account for a 'messed up MasterPage', I would assume that your Account folder has restricted access via authorization section of the web.config. This can be adjusted to allow access to certain resources; in the authorization section, you may have something like this:

<authorization>
    <deny users="?"/>
    <allow users="*"/>
</authorization>

The above will lock out access to all files that fall within the path that this is within scope of. Naturally your login page will be accessible, but maybe not resources such as CSS files and images - to allow these to be accessed by users not yet authenticated you can configure a custom location, as such:

<location path="pathToResources">
    <system.web>
        <authorization>
            <allow users="?"/>
        </authorization>
    </system.web>
</location>
这个俗人 2024-11-22 07:40:30

好吧,ASP.NET 从页面的“视点”解释相对链接,因此,如果页面位于文件夹中,则母版页相对链接将不再起作用。

这是我使用的解决方案,将您的头部内容包装在一个自定义控件中,该控件将执行 rebase:

<asp_custom:RebasingContainer ID="mainRebase" runat="server">
</asp_custom:RebasingContainer>  

for 并使用 runat=server 并像这样使用它们:

<link rel="stylesheet" type="text/css" href="~/css/reset.css"/>

注意“~”,它是 ASP.NET“从根开始”路径。

对于控件,请使用以下控件:

[ControlBuilder(typeof(RebasingContainerBuilder)),
  Designer("System.Web.UI.Design.ControlDesigner, System.Design, " +
  "Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
  ConstructorNeedsTag(false)]
public class RebasingContainer : HtmlGenericControl
{
    public RebasingContainer()
    {

    }

    protected override void RenderBeginTag(System.Web.UI.HtmlTextWriter writer)
    {  /*doesn't render it's own tag*/ }

    protected override void RenderEndTag(System.Web.UI.HtmlTextWriter writer)
    {/*doesn't render it's own tag*/}
}

该控件使用以下控件生成器:

public class RebasingContainerBuilder : ControlBuilder
{
    public override bool AllowWhitespaceLiterals()
    {
        return false;
    }

    public override Type GetChildControlType(string tagName, System.Collections.IDictionary attribs)
    {
        if (string.Equals(tagName, "link", StringComparison.OrdinalIgnoreCase))
        {
            return typeof(HtmlLink);
        }

        if (string.Equals(tagName, "script", StringComparison.OrdinalIgnoreCase)
            && attribs.Contains("src"))
        {
            //only rebase script tags that have a src attribute!
            return typeof(HtmlScript);
        }

        return null;
    }
}

脚本所在位置:

public class HtmlScript : HtmlGenericControl
{
    public HtmlScript() : base("script") { }

    public HtmlScript(string tag) : base(tag) { }

    public string Src
    {
        get
        {
            return this.Attributes["src"];
        }
        set
        {
            this.Attributes["src"] = value;
        }
    }

    protected override void RenderAttributes(HtmlTextWriter writer)
    {
        Src = ResolveClientUrl(Src);
        base.RenderAttributes(writer);
    }
}

在 web.config 中注册您的客户变基控件,然后您就可以开始了。例如:

<add assembly="__code" namespace="CustomControls" tagPrefix="asp_custom" />

如果您使用AppCode文件夹。

该解决方案将为您提供对分离的主网页和简单网页的运行时和设计时支持。

Well, ASP.NET interprets relative links from the "viewpoint" of the page, so if the page is in folder, your master page relative links will not work anymore.

Here is the solution that I use, wrap your head content in a custom control which will do the rebase:

<asp_custom:RebasingContainer ID="mainRebase" runat="server">
</asp_custom:RebasingContainer>  

for and use runat=server and use them like this:

<link rel="stylesheet" type="text/css" href="~/css/reset.css"/>

Note the "~" which is ASP.NET "go from root" path.

For controls, use this:

[ControlBuilder(typeof(RebasingContainerBuilder)),
  Designer("System.Web.UI.Design.ControlDesigner, System.Design, " +
  "Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"),
  ConstructorNeedsTag(false)]
public class RebasingContainer : HtmlGenericControl
{
    public RebasingContainer()
    {

    }

    protected override void RenderBeginTag(System.Web.UI.HtmlTextWriter writer)
    {  /*doesn't render it's own tag*/ }

    protected override void RenderEndTag(System.Web.UI.HtmlTextWriter writer)
    {/*doesn't render it's own tag*/}
}

The control uses following control builder:

public class RebasingContainerBuilder : ControlBuilder
{
    public override bool AllowWhitespaceLiterals()
    {
        return false;
    }

    public override Type GetChildControlType(string tagName, System.Collections.IDictionary attribs)
    {
        if (string.Equals(tagName, "link", StringComparison.OrdinalIgnoreCase))
        {
            return typeof(HtmlLink);
        }

        if (string.Equals(tagName, "script", StringComparison.OrdinalIgnoreCase)
            && attribs.Contains("src"))
        {
            //only rebase script tags that have a src attribute!
            return typeof(HtmlScript);
        }

        return null;
    }
}

Where the script is:

public class HtmlScript : HtmlGenericControl
{
    public HtmlScript() : base("script") { }

    public HtmlScript(string tag) : base(tag) { }

    public string Src
    {
        get
        {
            return this.Attributes["src"];
        }
        set
        {
            this.Attributes["src"] = value;
        }
    }

    protected override void RenderAttributes(HtmlTextWriter writer)
    {
        Src = ResolveClientUrl(Src);
        base.RenderAttributes(writer);
    }
}

Register your customer rebase control in web.config and you are ready to go. For example:

<add assembly="__code" namespace="CustomControls" tagPrefix="asp_custom" />

if you use AppCode folder.

This solution will give you runtime as well as design time support for separated master and simple web pages.

缱绻入梦 2024-11-22 07:40:30

只需使用这个:

将 / 放在 js 之前即可。

从这里引用:
在子文件夹中使用 JQuery 的情况母版页位于根文件夹中

simply use this:

putting / before js do the trick.

<script src="/js/jquery.js" type="text/javascript"></script>

Referenced from here :
Using JQuery in a Subfolder When the MasterPage is in the Root Folder

南笙 2024-11-22 07:40:30

当您的子文件夹中有 javascript 或 jQuery,并且根文件夹中有页面且子文件夹中有一些页面时,请执行以下操作:为母版页中的每个 javascript 文件添加两个链接:

例如:

<script src="Scripts/jquery.js" type="text/javascript"></script>
<script src="../Scripts/jquery.js" type="text/javascript"></script>

工作原理:子文件夹中的页面将被引用到带有 ../ 的链接,即

<script src="../Scripts/jquery.js" type="text/javascript"></script>

根文件夹中的页面将被引用到不带 ../ 的链接,即

<script src="../Scripts/jquery.js" type="text/javascript"></script>

提示:如果您无法使某个文件夹工作或其他,玩其中:~//.././ 将为您提供参考。

When you have javascript or jQuery in a subfolder and pages in the root folder with some in a subfolder, do this: add two links for each javascript file in your masterpage:

eg:

<script src="Scripts/jquery.js" type="text/javascript"></script>
<script src="../Scripts/jquery.js" type="text/javascript"></script>

How it works: Pages in the subfolders will be referenced to the link with ../, i.e

<script src="../Scripts/jquery.js" type="text/javascript"></script>

Pages in root folder will be referenced to the link without ../, i.e

<script src="../Scripts/jquery.js" type="text/javascript"></script>

Tip: If you can't get one folder working or the other, play with the: ~/, /, ../, and ./ one will reference it for you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文