Asp.Net实现伪静态

醉酒当歌 提交于 2019-11-30 12:48:58

一、起因

最近一个项目要实现伪静态,之前没接触过,故一切从零开始,开始网上查资料,方法大概有三种,但是我都试了好几个,都失败了。望有建议的博友给点建议,这里我实现了一种方式,是通过微软URLRewriter.dll实现的,觉得不错,故记录下来,大家一起学习,话不多说,上代码。

效果截图:

二、配置web.config

首先,新建项目。添加一个页面Default.aspx,用于测试。去下一个URLRewriter.dll,链接: https://pan.baidu.com/s/1hs3YNZm 密码: n6jx,添加引用即可;然后,开始配置web.config

1.调用URLRewriter.dll

 <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>

2.配置伪静态规则,至于规则的配置,可取google上去查。

复制代码
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Rule1">
          <match url="^123_t([0-9]+)\.html$" ignoreCase="false" />
          <action type="Rewrite" url="Default.aspx?id={R:1}" appendQueryString="false" />
        </rule>
        <rule name="Rule2">
          <match url="^123.html" ignoreCase="false" />
          <action type="Rewrite" url="Default.aspx" appendQueryString="false" />
        </rule>
        <rule name="Rule3">
          <match url="^job/l-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
          <action type="Rewrite" url="JobList.aspx?id={R:1}&amp;page={R:2}" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>
    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
复制代码

补充:网上也有另一种配置方法,这里也贴下,引用的dll也是一样的,如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
    <RewriterConfig>
    <Rules>
        <RewriterRule>
            <LookFor>~/Index.html</LookFor>
            <SendTo>~/Index.aspx</SendTo>
        </RewriterRule>
        <RewriterRule>
            <LookFor>~/Index/t_([0-9]*)/ID_([0-9]*).html$</LookFor>//如:http://localhost:60948/Index/t_8/ID_456.html
            <SendTo>~/Index.aspx?type=$1&id=$2</SendTo>s
        </RewriterRule>
    </Rules>
</RewriterConfig>
<system.web>
    <httpHandlers>
        <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
        <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
    </httpHandlers>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
</system.web>
<system.webServer>
    <handlers>
        <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler,URLRewriter" name="urlrewriter"/>
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
</system.webServer>

  

3.问题

每个人的电脑设置不同,可能会有各种不同的问题,但去百度基本能找到解决办法。本人对伪静态也是一知半解,大多也是查资料得来的信息,如有不同见解,望告知,谢谢。

http://www.wu0553.com/news/30169.html
http://www.wu0553.com/news/30166.html
http://www.wu0553.com/news/30162.html
http://www.wu0553.com/news/30158.html
http://www.wu0553.com/news/30153.html
http://www.wu0553.com/news/30149.html
http://www.wu0553.com/news/30145.html
http://www.wu0553.com/news/30138.html
http://www.wu0553.com/news/30130.html
http://www.wu0553.com/news/30123.html
http://www.wu0553.com/news/30111.html
http://www.wu0553.com/news/30102.html
http://www.wu0553.com/news/30090.html
http://www.wu0553.com/news/30080.html
http://www.wu0553.com/news/30071.html
http://www.wu0553.com/news/30063.html
http://www.wu0553.com/news/30054.html
http://www.wu0553.com/news/30048.html
http://www.wu0553.com/news/30043.html
http://www.wu0553.com/news/30035.html
http://www.wu0553.com/news/30028.html
http://www.wu0553.com/news/30022.html
http://www.wu0553.com/news/30016.html
http://www.wu0553.com/news/30005.html
http://www.wu0553.com/news/29996.html
http://www.wu0553.com/news/29984.html
http://www.wu0553.com/news/29973.html
http://www.wu0553.com/news/29960.html
http://www.wu0553.com/news/29951.html
http://www.wu0553.com/news/29940.html
http://www.wu0553.com/news/29930.html
http://www.wu0553.com/news/29923.html
http://www.wu0553.com/news/29916.html
http://www.wu0553.com/news/29906.html
http://www.wu0553.com/news/29897.html
http://www.wu0553.com/news/29888.html
http://www.wu0553.com/news/29881.html
http://www.wu0553.com/news/29872.html
http://www.wu0553.com/news/29861.html
http://www.wu0553.com/news/30117.html
http://www.wu0553.com/news/30105.html
http://www.wu0553.com/news/30093.html
http://www.wu0553.com/news/30081.html
http://www.wu0553.com/news/30070.html
http://www.wu0553.com/news/30061.html
http://www.wu0553.com/news/30052.html
http://www.wu0553.com/news/30046.html
http://www.wu0553.com/news/30038.html
http://www.wu0553.com/news/30032.html
http://www.wu0553.com/news/30025.html
http://www.wu0553.com/news/30018.html
http://www.wu0553.com/news/30008.html
http://www.wu0553.com/news/29997.html
http://www.wu0553.com/news/29983.html
http://www.wu0553.com/news/29970.html
http://www.wu0553.com/news/29958.html
http://www.wu0553.com/news/29946.html
http://www.wu0553.com/news/29934.html
http://www.wu0553.com/news/29925.html
http://www.wu0553.com/news/29919.html
http://www.wu0553.com/news/29909.html
http://www.wu0553.com/news/29898.html
http://www.wu0553.com/news/29887.html
http://www.wu0553.com/news/29878.html
http://www.wu0553.com/news/29869.html
http://www.wu0553.com/news/30298.html
http://www.wu0553.com/news/30297.html
http://www.wu0553.com/news/30296.html
http://www.wu0553.com/news/30295.html
http://www.wu0553.com/news/30294.html
http://www.wu0553.com/news/30293.html
http://www.wu0553.com/news/30292.html
http://www.wu0553.com/news/30291.html
http://www.wu0553.com/news/30290.html
http://www.wu0553.com/news/30289.html
http://www.wu0553.com/news/30288.html
http://www.wu0553.com/news/30287.html
http://www.wu0553.com/news/30286.html
http://www.wu0553.com/news/30285.html
http://www.wu0553.com/news/30284.html
http://www.wu0553.com/news/30283.html
http://www.wu0553.com/news/30282.html
http://www.wu0553.com/news/30281.html
http://www.wu0553.com/news/30280.html
http://www.wu0553.com/news/30278.html
http://www.wu0553.com/news/30275.html
http://www.wu0553.com/news/30272.html
http://www.wu0553.com/news/30268.html
http://www.wu0553.com/news/30265.html
http://www.wu0553.com/news/30260.html
http://www.wu0553.com/news/30255.html
http://www.wu0553.com/news/30249.html
http://www.wu0553.com/news/30240.html
http://www.wu0553.com/news/30234.html
http://www.wu0553.com/news/30231.html
http://www.wu0553.com/news/30227.html
http://www.wu0553.com/news/30222.html
http://www.wu0553.com/news/30214.html
http://www.wu0553.com/news/30211.html
http://www.wu0553.com/news/30208.html
http://www.wu0553.com/news/30204.html
http://www.wu0553.com/news/30200.html
http://www.wu0553.com/news/30196.html
http://www.wu0553.com/news/30193.html
http://www.wu0553.com/news/30189.html
http://www.wu0553.com/news/30187.html
http://www.wu0553.com/news/30183.html
http://www.wu0553.com/news/30179.html
http://www.wu0553.com/news/30174.html
http://www.wu0553.com/news/30171.html
http://www.wu0553.com/news/30165.html
http://www.wu0553.com/news/30160.html
http://www.wu0553.com/news/30151.html
http://www.wu0553.com/news/30146.html
http://www.wu0553.com/news/30136.html
http://www.wu0553.com/news/30125.html
http://www.wu0553.com/news/30113.html
http://www.wu0553.com/news/30101.html
http://www.wu0553.com/news/30088.html
http://www.wu0553.com/news/30076.html
http://www.wu0553.com/news/30066.html
http://www.wu0553.com/news/30056.html
http://www.wu0553.com/news/30047.html
http://www.wu0553.com/news/30040.html
http://www.wu0553.com/news/30031.html
http://www.wu0553.com/news/30023.html
http://www.wu0553.com/news/30014.html
http://www.wu0553.com/news/30002.html
http://www.wu0553.com/news/29988.html
http://www.wu0553.com/news/29976.html
http://www.wu0553.com/news/29962.html
http://www.wu0553.com/news/29948.html
http://www.wu0553.com/news/29858.html
http://www.wu0553.com/news/29848.html
http://www.wu0553.com/news/29843.html
http://www.wu0553.com/news/29839.html
http://www.wu0553.com/news/29852.html
http://www.wu0553.com/news/29845.html
http://www.wu0553.com/news/29841.html
http://www.wu0553.com/news/29838.html
http://www.wu0553.com/news/29834.html
http://www.wu0553.com/news/29828.html
http://market.szonline.net/amaz/11982.html
http://market.szonline.net/amaz/11981.html
http://market.szonline.net/amaz/11980.html
http://market.szonline.net/amaz/11979.html
http://market.szonline.net/amaz/11978.html
http://market.szonline.net/amaz/11977.html
http://market.szonline.net/amaz/11976.html
http://market.szonline.net/amaz/11975.html
http://market.szonline.net/amaz/11974.html
http://market.szonline.net/amaz/11973.html
http://market.szonline.net/amaz/11972.html
http://market.szonline.net/amaz/11971.html
http://market.szonline.net/amaz/11970.html
http://market.szonline.net/amaz/11969.html
http://market.szonline.net/amaz/11968.html
http://market.szonline.net/amaz/11967.html
http://market.szonline.net/amaz/11966.html
http://market.szonline.net/amaz/11965.html
http://market.szonline.net/amaz/11964.html
http://market.szonline.net/amaz/11963.html
http://market.szonline.net/amaz/11962.html
http://market.szonline.net/amaz/11961.html
http://market.szonline.net/amaz/11960.html
http://market.szonline.net/amaz/11959.html
http://market.szonline.net/amaz/11958.html
http://market.szonline.net/amaz/11957.html
http://market.szonline.net/amaz/11956.html
http://market.szonline.net/amaz/11955.html
http://market.szonline.net/amaz/11954.html
http://market.szonline.net/amaz/11953.html
http://market.szonline.net/amaz/11952.html
http://market.szonline.net/amaz/11951.html
http://market.szonline.net/amaz/11950.html
http://market.szonline.net/amaz/11949.html
http://market.szonline.net/amaz/11948.html
http://market.szonline.net/amaz/11947.html
http://market.szonline.net/amaz/11946.html
http://market.szonline.net/amaz/11945.html
http://market.szonline.net/amaz/11944.html
http://market.szonline.net/amaz/11943.html
http://www.wu0553.com/news/29824.html
http://www.wu0553.com/news/29818.html
http://www.wu0553.com/news/29812.html

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!