即使在子目錄中,基於URL的方法也應該可以正常工作。因爲你提到「子目錄」而不是「控制器/動作」,我假設你的應用程序是用ASP.NET WebForms而不是MVC實現的。
如果是這樣的話,你的URL重寫你的請求在您的Application_BeginRequest
:
public void Application_BeginRequest(object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
HttpContext ctx = app.Context;
string PathAndQuery = ctx.Request.Url.PathAndQuery;
// parse the PathAndQuery and if it is of the form
// en/Subdir1/Subdir2/resource.aspx
// split it into [en] (virtual part) and [Subdir1/Subdir2/resource.aspx] (physical part)
string VirtualPart = GetVirtualPart(PathAndQuery);
string PhysicalPart = GetPhysicalPart(PathAndQuery);
ctx.RewritePath(PhysicalPart);
}
通過這種方法,你必須在文件系統和形式en\Subdir1\Subdir2\resource.aspx
的請求你的物理結構被正確地路由到Subdir1\Subdir2\resource.aspx
。
雖然示例顯示手動重寫,但如果它符合您的需要,則可以使用任何現有的重寫技術。
這只是爲了讓你開始。但是,如果您在實施網址重寫時遇到任何具體問題,我認爲您必須提出其他具體問題,以便人們可以幫助解決具體問題。如果你只是說我已經花了幾天的時間,它不起作用那麼它是不可能的,以幫助你與你的具體做法。