ASP.NET MVC ActionLink 与 URL 重写

发布于 2024-08-29 03:58:49 字数 457 浏览 8 评论 0原文

有一个 ASP.NET MVC 2 Web 应用程序,我们将其称为 myapp.com。我想要动态子域(用户创建的类别),例如something.myapp.com。所以我已经设置了 URL 重写和规则重写 Something.myapp.com -> myapp.com/something (接下来由 MVC 处理..)。但是,第一个 ActionLink 会引发异常

System.Web.HttpException: Cannot use aleading .. to exit above the top Directory,

因为显然,该 URL 仍然是 Something.myapp.com。有什么优雅的解决方案吗?我不想重定向(我想在浏览器中保留 URL some.myapp.com)。另外,我不喜欢编写自定义 ActionLink 的想法,这是 MVC 中的一些最基本的东西...

谢谢大家:)

Roman

There is a ASP.NET MVC 2 web app, lets call it myapp.com. I want dynamic subdomains (user created categories) like something.myapp.com. So i have set up URL rewrite with rule rewriting something.myapp.com -> myapp.com/something (which is handled by MVC next..). But, the first ActionLink throws an exception

System.Web.HttpException: Cannot use a leading .. to exit above the top directory

because, obviously, the URL is still something.myapp.com for it. Is there any elegant solution for this ? I dont want to redirect (I want to keep URL something.myapp.com in browser). Also I dont like the idea of writing custom ActionLink, some of the most basic stuff in MVC...

thanx guys :)

Roman

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

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

发布评论

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

评论(1

别理我 2024-09-05 03:58:49

您首先要了解的是路由和重写之间的区别。这个博客可以最好地描述这一点:

http://www. coderjournal.com/2010/03/difference- Between-routing-rewriting/

作为本文的后续内容,还创建了一个用于编辑路由内联重写的项目,以帮助演示差异,更重要的是它们如何能够一起使用。

http://www.coderjournal.com/2010/03 /editable-mvc-routes-apache-style/

但是为了更直接地回答你的问题,你需要确保 URL 重写器在路由之前得到处理,以便提前为你修改和标准化所有内容。

The first thing you have to understand is the difference between Routing and Rewriting. This can best be described by this blog:

http://www.coderjournal.com/2010/03/difference-between-routing-rewriting/

As a follow up to the article a project for editing Routing inline with Rewriting was also created, to help demonstrate the differences and more importantly how they can be used together.

http://www.coderjournal.com/2010/03/editable-mvc-routes-apache-style/

But to answer your question more directly, you need to make sure the URL Rewriter is getting processed before the Routing, so that everything is modified and normalized for you ahead of time.

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