是否可以在我的 Web 应用程序中覆盖相对路径 ~/ ?
背景故事
我目前正在更新现有的 Web 应用程序以支持多租户环境。今天,我们当前在 http://www.example.com/MyApp 上托管一个应用程序,但现在我们必须能够在同一个 Web 应用程序上支持多个客户端。
因此每个客户端应该能够通过如下 URL 访问应用程序: http://www.example.com/MyApp/Client1
http://www.example.com/MyApp/Client2
Web 应用程序是 ASP.NET我们也正在升级以使用 .NET 4 的 webforms 应用程序。我已经实现了 ASP.NET 4 中可用的新路由,并且已经放置了适当的路由来支持多租户架构。
示例 URL http://www.example.com/MyApp/Client1/SomeModule/ SomePage.aspx 将路由到并执行 /MyApp/SomeModule/SomePage.aspx
并且我可以从 RouteData 中访问客户端部分。
但是...
主要问题:
我们在应用程序的许多部分都有使用 url 的链接,例如 ~/SomeModule/SomePage.aspx
,因此当它们呈现到浏览器时,它们仍然会显示 /MyApp/SomeModule/SomePage。 aspx
,但我真正想要的是让它包含我的路由值之一来注入客户端页面,例如 MyApp/Client1/SomeModule/SomePage.aspsx
有没有办法覆盖什么~/
意味着在我的整个应用程序中而不需要遍历我的整个应用程序并更新链接?
Back Story
I am currently updating an existing web application to support a multi-tenant environment. Today we current host an application on http://www.example.com/MyApp, but now we must be able to support multiple clients on the same web application.
So each client should be able to access the application through urls like:
http://www.example.com/MyApp/Client1
http://www.example.com/MyApp/Client2
The web application is an ASP.NET webforms app that we are also upgrading to use .NET 4. I have already implemented the new routing available in ASP.NET 4, and I haven already put the appropriate routes in place to support the multi-tenant architecture.
The example URL http://www.example.com/MyApp/Client1/SomeModule/SomePage.aspx will route to and execute /MyApp/SomeModule/SomePage.aspx
and I have access to the client part from within the RouteData.
BUT...
Main Question:
We have links in many parts of the application that use url's like ~/SomeModule/SomePage.aspx
, so when they render out to the browser they will still show /MyApp/SomeModule/SomePage.aspx
, but what I really want is to have it contain one of my route values to inject the client page like MyApp/Client1/SomeModule/SomePage.aspsx
Is there a way to override what the ~/
means throughout my application without going through my entire app and updating the links?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将 Page 对象上的
AppRelativeVirtualPath
属性设置为所需的路径。但是您必须在创建处理程序后首先执行此操作,因为添加到Controls
集合中的每个控件都将从其父级继承此值。实现此目的的一种方法是子类化
PageHandlerFactory
类,该类负责在请求 .aspx 文件时创建Page
实例。使用以下代码覆盖GetHandler
:当然,更改 web.config 中 httpHandlers 下的注册以指向新的工厂类。
Set the
AppRelativeVirtualPath
property on your Page object to your desired path. But you have to do it as the first thing after your handler is created, since every control added to yourControls
-collection will inherit this value from its parent.A way to do this is to subclass the
PageHandlerFactory
class which is responsible for creating aPage
instance when your request a .aspx file. Override theGetHandler
with the following code:and of course change the registration under httpHandlers in your web.config to point to your new factory class.
我似乎不可能覆盖
~/
。我们决定采用不同的方法并创建实用方法来帮助管理多租户环境中的链接和路径。我看到实际实现此目的的最佳选择是实现 IUrlResolutionService,但我们无法成功完成这项工作。
I doesn't seem like overriding the
~/
is possible. We have decided to take a different approach and create utility methods to help manage links and paths within our multi-tenant environment.The best option I saw to actually accomplish this is to implement
IUrlResolutionService
, but we were unable to make this work successfully.