ASP.NET URL Rewriting in very easy way

别说谁变了你拦得住时间么 提交于 2020-01-26 00:38:26

问题


I want to know how to make SEF URL for web pages. After a little googling I have found many techniques, but all of them are so complicated. I do not need them. Is there any way to make SEF URL which is very easy to implement?


回答1:


First download this reference .

Then import it to your web site.

under <configuration> node type this:

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

The next step is typing the following code under <system.web> node:

the next one is putting the following line just before </configuration> tag:

<urlrewritingnet configSource="RewriteRules.config"/>

We are almost done!

Create a new .config file which matches the tag's configResource parameter. I preferred "RewriteRules.config".

Then it is time to create rewriting rules on RewriteRules.config file:

<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage="Default.aspx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
    <rewrites>
        <add name="DetailPageRule" virtualUrl="^~/VirtualDetailPageName/(.*)/(.*).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/RealDetailPage.aspx?param1=$1&amp;param2=$2" ignoreCase=" true"/>
    </rewrites>
</urlrewritingnet>

If you have more or less parameters you can change the count of (.)'s. Here there are only two parameters (param1 and param2), so there are only two (.) strings.

Final Step is giving links in according to the rules you have created.

It is simple and fast. But I do not know if there are drawbacks or any security issues.



来源:https://stackoverflow.com/questions/14876329/asp-net-url-rewriting-in-very-easy-way

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