简体   繁体   English

ASP.NET MVC ActionLink与URL重写

[英]ASP.NET MVC ActionLink vs. URL Rewrite

There is a ASP.NET MVC 2 web app, lets call it myapp.com. 有一个ASP.NET MVC 2 Web应用程序,可以称之为myapp.com。 I want dynamic subdomains (user created categories) like something.myapp.com. 我想要诸如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..). 所以我用规则重写something.myapp.com-> myapp.com/something(接下来由MVC处理)来设置URL重写。 But, the first ActionLink throws an exception 但是,第一个ActionLink抛出异常

System.Web.HttpException: Cannot use a leading .. to exit above the top directory System.Web.HttpException:无法使用前导..退出顶层目录

because, obviously, the URL is still something.myapp.com for it. 因为很明显,URL仍然是它的something.myapp.com。 Is there any elegant solution for this ? 有什么优雅的解决方案吗? I dont want to redirect (I want to keep URL something.myapp.com in browser). 我不想重定向(我想在浏览器中保留URL something.myapp.com)。 Also I dont like the idea of writing custom ActionLink, some of the most basic stuff in MVC... 我也不喜欢编写自定义ActionLink的想法,这是MVC中最基本的内容...

thanx guys :) thanx伙计们:)

Roman 罗曼

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/ 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/ 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. 但是要更直接地回答您的问题,您需要确保在路由之前处理URL重写器,以便提前为您修改和标准化所有内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM