如何重写url从我的网址中删除default.aspx [英] How to rewrite url to remove default.aspx from my url

查看:88
本文介绍了如何重写url从我的网址中删除default.aspx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用urlrewrite重写url以从www.mydomain.com \ default中删除default.aspx。 Aspx

How to rewrite url using urlrewrite to remove default.aspx from www.mydomain.com\default. Aspx

推荐答案

看这里开始:



http://weblogs.asp.net/scottgu/tip-trick-url-rewriting-with-asp-net [ ^ ]



http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module [< a href =http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module\"target =_ blanktitle =新窗口> ^ ]



https://github.com/ aspnetde / UrlRewritingNet [ ^ ]



使用ASP.NET重写URL的示例 [ ^ ]
Look here to get started:

http://weblogs.asp.net/scottgu/tip-trick-url-rewriting-with-asp-net[^]

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

https://github.com/aspnetde/UrlRewritingNet[^]

An Example of URL Rewriting With ASP.NET[^]


我真的相信default.aspx是应用程序中的默认登录页面,如果是这样,IIS即使您在没有将default.aspx连接到最后的URL的情况下转到URL,也不会要求它。因此,您可以尝试使用没有它的页面。



您可以使用Visual C#,



I really believe that the default.aspx is the default landing page in your application, if so, IIS would not bother asking for it even if you go to the URL without having the default.aspx concatenated to the URL at the end. So, you can try using the page without it.

You can use Visual C# for this,

// get the URL
var url = Request.Url;
// get the page user's at
// General URL: "http://www.example.com/default.aspx"
// Get the string at the index 4 (3 if talking zero based)
var page = url.Split('/')[3];
// If the page is default.aspx
if(page == "default.aspx") {
   // Redirect him
   Response.Redirect("~/");
}





您可以编辑web.config文件并在其中编写此代码,以防止default.aspx进入你的网址。 参考





You can edit your web.config file and write this code in it, to prevent the default.aspx in your URL. Reference.

<rewrite>
    <rules>
        <rule name="san aspx">
          <!--Removes the .aspx extension for all pages.-->
          <match url="(.*)" />
          <conditions logicalgrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchtype="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchtype="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="{R:1}.aspx" />
        </rule>
    </rules>
</rewrite>





..并且相信我,有许多(和许多)其他方法可用于执行此类任务。网址路由就是其中之一。



.. and trust me, there are many (and many) other methods that you can use to perform such tasks. Url Routing is one of them.


这篇关于如何重写url从我的网址中删除default.aspx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆