常规域路径和安全域路径之间的 Webresource.axd 问题

发布于 2024-07-09 20:54:48 字数 478 浏览 5 评论 0原文

在我们的设置中,IIS 7 设置中有两个不同的网站指向相同的物理路径。 第一个绑定 http://websitename.domain.com/(虚拟根 ~ 是 /)

,第二个位于 https://webserver.domain.com/用户 ID/网站名称所以虚拟root ~ 是 /userid/websitename)。 我们使用第二个来保证每个网站的安全。

这会导致加载生成的 css 的 Webresources.axd 文件和 AJAX.net 工具包的 javascript 出现问题。

有没有办法修改这些生成的资源文件的路径。 或者以某种方式设置每个应用程序的虚拟根路径。

In our setup there are two different websites in IIS 7 setup that point to the same physical path. One with the binding http://websitename.domain.com/ (virtual root ~ is /)

and the second at https://webserver.domain.com/userid/websitename (so the virtual root ~ is /userid/websitename). We use the second for secure aspects of each website.

This causes a problem with the loading of the Webresources.axd files for generated css, and javascript for the AJAX.net toolkit.

Is there a way to have the path to these generated resource files modified. Or somehow set the virtual root path per application.

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

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

发布评论

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

评论(1

岁吢 2024-07-16 20:54:48

我找到了一种解决方案,使用 Render() 方法将 url 路径替换为正确的路径。 此论坛帖子提供了有关此解决方案的信息。 我必须修改它来检查 Request.Url 以查看页面请求来自哪个域。

protected override void Render(HtmlTextWriter writer)
{
     try
     {                  
          StringBuilder renderedOutput = new StringBuilder();    
          StringWriter strWriter = new StringWriter(renderedOutput);    
          HtmlTextWriter tWriter = new HtmlTextWriter(strWriter);    
          base.Render(tWriter);

          //this string is to be searched for src="/" mce_src="/" and replace it with correct src="./" mce_src="./". 

          string s = renderedOutput.ToString();
          s = Regex.Replace(s, "(?<=<img[^>]*)(src=\\\"/)", "src=\"./", RegexOptions.IgnoreCase);
          s = Regex.Replace(s, "(?<=<script[^>]*)(src=\\\"/)", "src=\"./", RegexOptions.IgnoreCase);
          s = Regex.Replace(s, "(?<=<a[^>]*)(href=\\\"/)", "href=\"./", RegexOptions.IgnoreCase);

          writer.Write(s);
      }
      catch
      {
      }
  }
}

I found one solution, using the Render() method to replace the url paths with the correct one. This forum post has info on this solution. I'll have to modify it to check the Request.Url to see which domain the page request is coming from.

protected override void Render(HtmlTextWriter writer)
{
     try
     {                  
          StringBuilder renderedOutput = new StringBuilder();    
          StringWriter strWriter = new StringWriter(renderedOutput);    
          HtmlTextWriter tWriter = new HtmlTextWriter(strWriter);    
          base.Render(tWriter);

          //this string is to be searched for src="/" mce_src="/" and replace it with correct src="./" mce_src="./". 

          string s = renderedOutput.ToString();
          s = Regex.Replace(s, "(?<=<img[^>]*)(src=\\\"/)", "src=\"./", RegexOptions.IgnoreCase);
          s = Regex.Replace(s, "(?<=<script[^>]*)(src=\\\"/)", "src=\"./", RegexOptions.IgnoreCase);
          s = Regex.Replace(s, "(?<=<a[^>]*)(href=\\\"/)", "href=\"./", RegexOptions.IgnoreCase);

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