0

私はasp.net 4のマップページルートのGlobal.asaxページでこのコードを使用します

    protected void RegistreRoutes(System.Web.Routing.RouteCollection routes)
    {
        routes.MapPageRoute(
        "Lerning-browse", "Learning-CSharp", "~/CSharp.aspx");
    }

    protected void Application_Start(object sender, EventArgs e)
    {
        RegistreRoutes(System.Web.Routing.RouteTable.Routes);
    }

ユーザーがmysite.com/Learning-CSharpを URL に入力する場合。MapPageRoute が機能し、mysite.com/Learning-CSharp のURL を取得します。ただし、ユーザーが URL にmysite.com/CSharp.aspxを入力すると、URL にmysite.com/CSharp.aspxが表示されます。

URL にmysite.com/CSharp.aspxを取得したくありません。ユーザーがURLにmysite.com/CSharp.aspxを入力すると、 mysite.com/Learning-CSharpに変換されます

4

3 に答える 3

0
protected void RegistreRoutes(System.Web.Routing.RouteCollection routes)
{
    routes.Ignore("{*allaspx}", new { allaspx = @".*\.aspx(/.*)?" });
    routes.Ignore("{*allcss}", new { allcss = @".*\.css(/.*)?" });
    routes.Ignore("{*alljpg}", new { alljpg = @".*\.jpg(/.*)?" });
    routes.Ignore("{*alljs}", new { alljs = @".*\.js(/.*)?" });
    routes.Add(new System.Web.Routing.Route("{resource}.css/{*pathInfo}", new              
    System.Web.Routing.StopRoutingHandler()));
    routes.Add(new System.Web.Routing.Route("{resource}.js/{*pathInfo}", new 
    System.Web.Routing.StopRoutingHandler()));

    routes.MapPageRoute(
         "HomeRoute",
         "",
         "~/default.aspx"
     );
    routes.MapPageRoute(
    "Lerning-browse", "Learning-CSharp", "~/CSharp.aspx");
}

protected void Application_Start(object sender, EventArgs e)
{
    RegistreRoutes(System.Web.Routing.RouteTable.Routes);
}
于 2013-09-15T10:34:23.973 に答える
0

IISのURL書き換えのお仕事です。

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

次の行に沿った何かがそれを行うはずです:

<rewrite>
    <rules>
        <rule name="Rewrite to article.aspx">
            <match url="(.*)(\.aspx)$" />
            <action type="Rewrite" url="{R:1}" />
        </rule>
    </rules>
</rewrite>

クエリ文字列もサポートする場合は、これをさらに変更する必要があります。

于 2013-09-15T10:35:30.150 に答える
0

管理する必要があるルートが 1 つまたは 2 つしかない場合、より簡単なプロセスは、それらをハードコードされたリダイレクトとして web.config ファイルに追加することです。

何かのようなもの:

<location path="CSharp.aspx">
    <system.webServer>
        <httpRedirect enabled="true" destination="/Learning-CSharp" exactDestination="true" httpResponseStatus="Permanent" />
    </system.webServer>
</location>

私はこのタイプのリダイレクトを多くの古い Web サイトで使用してきました。特に、新しいコード ベースに移行する場合はそうです。つまり、Web フォームから MVC に移行します。

お役に立てれば。

于 2013-09-15T22:54:11.667 に答える