Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何去掉URL中的实际文件名?_Asp.net_Iis_Url - Fatal编程技术网

Asp.net 如何去掉URL中的实际文件名?

Asp.net 如何去掉URL中的实际文件名?,asp.net,iis,url,Asp.net,Iis,Url,例如,这个url是http://stackoverflow.com/questions/ask,而不是像http://stackoverflow.com/questions/ask.aspx。我该怎么做 当web服务器实现将给定URL模式映射到要提供的实际内容的处理程序时,就会发生这种情况 在这个站点中,它可能来自MVC框架的使用(猜测) 在windows IIS上,您可以使用以下技巧和工具: -IIS解决方案 -ASP.NET 404页面解决方案添加对assembly System.Web.R

例如,这个url是
http://stackoverflow.com/questions/ask
,而不是像
http://stackoverflow.com/questions/ask.aspx
。我该怎么做

当web服务器实现将给定URL模式映射到要提供的实际内容的处理程序时,就会发生这种情况

在这个站点中,它可能来自MVC框架的使用(猜测)


在windows IIS上,您可以使用以下技巧和工具:

-IIS解决方案


-ASP.NET 404页面解决方案添加对assembly System.Web.Routing的引用,然后将以下内容添加到global.asax文件中:

protected void Application_Start(object sender, EventArgs e)
{
     RegisterRoutes(RouteTable.Routes);
}

public static void RegisterRoutes(RouteCollection routes)
{
    routes.MapPageRoute("",
        "questions/ask/{question}",
        "~/questions/ask.aspx");
}

如果您的问题不是特定于aspx页面的,那么您可以在任何运行apache的Web服务器上使用.htaccess文件(和mod_rewrite,但这几乎是所有的Web服务器)来完成这项工作

在本网站上查看有关的各种问题,或在线查看许多简单教程

基本上,您可以将一个特殊文件
.htaccess
放在您希望受影响的目录的根目录中,即

您可以使用
about\u-us/details
php代替
about\u-us/details.php

这是一个非常简单的例子

RewriteEngine on 
Options +FollowSymlinks

RewriteRule ^questions/ask ../questions/ask.aspx [L]

允许您使用不必映射到网站中特定文件的URL。因为URL不必映射到文件,所以您可以使用描述用户行为的URL,从而更容易被用户理解。asp.net路由是通用功能还是MVC的一个组件(或者这是否重要)@Gabriel,由于使用古老的和非推荐的解决方案的答案已经被接受,我认为这无关紧要