ASP.NET MVC ActionLink 与 URL 重写
有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您首先要了解的是路由和重写之间的区别。这个博客可以最好地描述这一点:
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.