如何使用Visual Web Development服务器配置无扩展名URL?

时间:2022-06-06 11:26:36

I'm using Visual Studios' built-in ASP.NET Development Server (VWD) to test my web site during development.

我正在使用Visual Studios的内置ASP.NET开发服务器(VWD)在开发过程中测试我的网站。

I would like this ASP.NET web site to use extensionless URLs (pages don't require the aspx extension). Ordinarily I would configure a custom 404 in IIS that directs to an ASPX page. How would I do this with VWD?

我希望这个ASP.NET网站使用无扩展名的URL(页面不需要aspx扩展名)。通常我会在IIS中配置一个指向ASPX页面的自定义404。我怎么用VWD做这件事?

P.S. This is not an ASP.NET MVC web site.

附:这不是ASP.NET MVC网站。

4 个解决方案

#1


Here is an example of a Web.Config using UrlRewritingNet. Doing this will allow you to do extensionless Rewriting without having to write any HttpModule or anything like that.

以下是使用UrlRewritingNet的Web.Config示例。执行此操作将允许您进行无扩展重写,而无需编写任何HttpModule或类似的东西。

(full article here)

(全文在这里)

Note: this requires IIS7 as it is using the system.webServer section of the web.config.

注意:这需要IIS7,因为它使用web.config的system.webServer部分。


<configSections>  
    <section name="urlrewritingnet"    
             restartOnExternalChanges="true"    
             requirePermission="false"    
             type="UrlRewritingNet.Configuration.UrlRewriteSection,  UrlRewritingNet.UrlRewriter" />  
</configSections>  

<system.webServer>  
    <modules runAllManagedModulesForAllRequests="true">   
        <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />  
    </modules>  
</system.webServer>  


<urlrewritingnet rewriteOnlyVirtualUrls="true"    
                 contextItemsPrefix="QueryString"    
                 xmlns="http://www.urlrewriting.net/schemas/config/2006/07">   
    <rewrites>  
        <!--Enable HTM(L) Extensions-->  
        <add name="pageHTML"    
             virtualUrl="^~/(.+).htm(.*)"    
             redirectMode="Permanent"  
             rewriteUrlParameter="ExcludeFromClientQueryString"    
             destinationUrl="~/$1.aspx"    
             ignoreCase="true" />  
        <!--Fix the WebResource JS Error-->  
        <add name="WebResourceFix"    
             virtualUrl="^~/WebResource.axd(.*)"  
             rewriteUrlParameter="IncludeQueryStringForRewrite"    
             destinationUrl="~/WebResource.axd$1"    
             ignoreCase="true"/>   
        <!--Fix the ScriptResource JS Error-->  
        <add name="ScriptResource"    
             virtualUrl="^~/ScriptResource.axd(.*)"  
             rewriteUrlParameter="IncludeQueryStringForRewrite"    
             destinationUrl="~/ScriptResource.axd$1"    
             ignoreCase="true"/>   
        <!--Allow Extensionless Page Extensions-->  
        <add name="pageExtensionless"  
             virtualUrl="^~/(.+)$"  
             redirectMode="Permanent"  
             rewriteUrlParameter="ExcludeFromClientQueryString"  
             destinationUrl="~/$1.aspx"  
             ignoreCase="true" />  
    </rewrites>  
</urlrewritingnet>  

#2


There's nothing special you need to do. Just remove the .aspx extension from the ASPX page file and it should work fine with VWD. The Visual Studio designer will probably complain that there's no build provider registered for the extension '', but you can just ignore it. Then you can reference the page without extension:

你不需要做什么特别的事情。只需从ASPX页面文件中删除.aspx扩展名,它就可以与VWD一起使用。 Visual Studio设计人员可能会抱怨没有为扩展程序注册的构建提供程序,但您可以忽略它。然后你可以参考没有扩展名的页面:

http://localhost:2181/Default

<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Hello World
    </div>
    </form>
</body>
</html>

#3


If you are trying to get something like http://localhost:3000/value to go to http://localhost:3000/page.aspx?tag=value then you can use an HttpModule, which is also a good alternative to a 404 redirect. I used to do the same thing too.

如果你想获得像http:// localhost:3000 / value这样的东西去http:// localhost:3000 / page.aspx?tag = value那么你可以使用HttpModule,它也是一个很好的替代方案。 404重定向。我过去常常做同样的事情。

I posted some example code in a previous question.

我在上一个问题中发布了一些示例代码。

#4


All you need to do is add the module in two different places within your web.config...

您需要做的就是在web.config中的两个不同位置添加模块...

<system.web>
    <pages theme="Default" />
    <httpModules>
        <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
    </httpModules>
</system.web>


<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="UrlRewriteModule"/>
        <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
    </modules>
</system.webServer>

The first one is to add it to your httpModules with will work in your VS Dev environment, and the second one will for IIS7

第一个是将它添加到您的httpModules中,它将在您的VS Dev环境中工作,第二个将用于IIS7

#1


Here is an example of a Web.Config using UrlRewritingNet. Doing this will allow you to do extensionless Rewriting without having to write any HttpModule or anything like that.

以下是使用UrlRewritingNet的Web.Config示例。执行此操作将允许您进行无扩展重写,而无需编写任何HttpModule或类似的东西。

(full article here)

(全文在这里)

Note: this requires IIS7 as it is using the system.webServer section of the web.config.

注意:这需要IIS7,因为它使用web.config的system.webServer部分。


<configSections>  
    <section name="urlrewritingnet"    
             restartOnExternalChanges="true"    
             requirePermission="false"    
             type="UrlRewritingNet.Configuration.UrlRewriteSection,  UrlRewritingNet.UrlRewriter" />  
</configSections>  

<system.webServer>  
    <modules runAllManagedModulesForAllRequests="true">   
        <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />  
    </modules>  
</system.webServer>  


<urlrewritingnet rewriteOnlyVirtualUrls="true"    
                 contextItemsPrefix="QueryString"    
                 xmlns="http://www.urlrewriting.net/schemas/config/2006/07">   
    <rewrites>  
        <!--Enable HTM(L) Extensions-->  
        <add name="pageHTML"    
             virtualUrl="^~/(.+).htm(.*)"    
             redirectMode="Permanent"  
             rewriteUrlParameter="ExcludeFromClientQueryString"    
             destinationUrl="~/$1.aspx"    
             ignoreCase="true" />  
        <!--Fix the WebResource JS Error-->  
        <add name="WebResourceFix"    
             virtualUrl="^~/WebResource.axd(.*)"  
             rewriteUrlParameter="IncludeQueryStringForRewrite"    
             destinationUrl="~/WebResource.axd$1"    
             ignoreCase="true"/>   
        <!--Fix the ScriptResource JS Error-->  
        <add name="ScriptResource"    
             virtualUrl="^~/ScriptResource.axd(.*)"  
             rewriteUrlParameter="IncludeQueryStringForRewrite"    
             destinationUrl="~/ScriptResource.axd$1"    
             ignoreCase="true"/>   
        <!--Allow Extensionless Page Extensions-->  
        <add name="pageExtensionless"  
             virtualUrl="^~/(.+)$"  
             redirectMode="Permanent"  
             rewriteUrlParameter="ExcludeFromClientQueryString"  
             destinationUrl="~/$1.aspx"  
             ignoreCase="true" />  
    </rewrites>  
</urlrewritingnet>  

#2


There's nothing special you need to do. Just remove the .aspx extension from the ASPX page file and it should work fine with VWD. The Visual Studio designer will probably complain that there's no build provider registered for the extension '', but you can just ignore it. Then you can reference the page without extension:

你不需要做什么特别的事情。只需从ASPX页面文件中删除.aspx扩展名,它就可以与VWD一起使用。 Visual Studio设计人员可能会抱怨没有为扩展程序注册的构建提供程序,但您可以忽略它。然后你可以参考没有扩展名的页面:

http://localhost:2181/Default

<%@ Page Language="C#"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Hello World
    </div>
    </form>
</body>
</html>

#3


If you are trying to get something like http://localhost:3000/value to go to http://localhost:3000/page.aspx?tag=value then you can use an HttpModule, which is also a good alternative to a 404 redirect. I used to do the same thing too.

如果你想获得像http:// localhost:3000 / value这样的东西去http:// localhost:3000 / page.aspx?tag = value那么你可以使用HttpModule,它也是一个很好的替代方案。 404重定向。我过去常常做同样的事情。

I posted some example code in a previous question.

我在上一个问题中发布了一些示例代码。

#4


All you need to do is add the module in two different places within your web.config...

您需要做的就是在web.config中的两个不同位置添加模块...

<system.web>
    <pages theme="Default" />
    <httpModules>
        <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
    </httpModules>
</system.web>


<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
        <remove name="UrlRewriteModule"/>
        <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
    </modules>
</system.webServer>

The first one is to add it to your httpModules with will work in your VS Dev environment, and the second one will for IIS7

第一个是将它添加到您的httpModules中,它将在您的VS Dev环境中工作,第二个将用于IIS7