Asp.net uses pseudo static-Modify the webconfig configuration file.

Source: Internet
Author: User

Use rewrite to set rules on IIS to implement pseudo-static state. In this way, debugging will not be available during development in vs. If you use IIS for publishing, the file cannot be found. Of course, there must be other methods to implement pseudo-static. You don't need to set anything in IIS. You only need one. NET components and webconfig File Settings are OK. Let's take a look at this. I have used a very small number of times and are afraid to forget it every time, So I recorded it, if you forget it next time, you don't need to use Google.

You have to download a urlrewriter. dll component online. This class library is available on the Internet.Source codeOf course, there are also compiled DLL files, you just need to put the DLL file Coty under the bin of your site, right-click the website, add reference, browse and select this DLL file.

You need to configure it in webconfig.

1. Add the following nodes in <system. Web> and </system. Web> of Web. config:
<Httpmodules>
<Add type = "urlrewriter. modulerewriter, urlrewriter" name = "modulerewriter"/>
</Httpmodules>

2. Add the following nodes in <configuration> and </configuration> of Web. config:

<Configsections> <section name = "rewriterconfig" type = "urlrewriter. config. Regular, urlrewriter"/> </configsections> <rewriterconfig> <rules> <rewriterrule> <lookfor> ~ /Default/. html </lookfor> <sendto> ~ /Default. aspx </sendto> </rewriterrule> <lookfor> ~ /Detial _ ([0-9] *)/. html </lookfor> <sendto> ~ /Detial. aspx? Id = $1 </sendto> </rewriterrule> <lookfor> ~ /List_p ([0-9] *)/. html </lookfor> <sendto> ~ /List. aspx? Page = $1 </sendto> </rewriterrule> <lookfor> ~ /Double_t ([0-9] *) _ p ([0-9] *)/. html </lookfor> <sendto> <! -- [CDATA [~ /Double. aspx? Type = $1 & page = $2] --> </sendto> </rewriterrule> <lookfor> ~ /About _ (. *)/. html </lookfor> <sendto> ~ /About. aspx? Title = $1 </sendto> </rewriterrule> </rules> </rewriterconfig>

After setting the preceding two steps, you can basically run it. The <rewriterrule/> label contains a rewritten module, and the <lookfor/> label contains the rewritten address, <sendto/> is the original address. You should have noticed that I have written two groups of <rewriterrule/>. The first group is used for the single-parameter address, and the other is used for multi-parameter dynamic files.

I believe that if you have used to configure pseudo-static rules in IIS, it is natural to configure rules in webconfig. If not, you can look for regular expressions, no need to be proficient.

Of course, there are some precautions for this method:
1. You cannot use Windows to authenticate user permissions. Use Form for authentication. In web. config, configure it as: <Authentication mode = "forms"/>
2. The path obtained using request. servervariables ["script_name"] is still: showplay. asp? Vid = 1
3. If the address to be rewritten is sent back, the address to be overwritten will be showplay. asp? Vid = 1
4. The suffix name must be. aspx. If it is another custom suffix name, for example,. net, map. Net to aspnet_isapi.dll in IIS.

 

Five pages

About. aspx

<Form ID = "form1" runat = "server"> <div> This is the aboutlpage. Is urlabout.aspxstill about.html? <Br/> <a href = "default.html" mce_href = "default.html"> homepage </a> <br/>  

CSCode:

// About page public partial class about: system. web. UI. page {protected void page_load (Object sender, eventargs e) {String title = request ["title"]. tostring (); textbox1.text = "name is" + title ;}}// public partial class detial: system. web. UI. page {protected void page_load (Object sender, eventargs e) {string id = request ["ID"]. tostring (); textbox1.text = "id =" + id ;}// double. ASPX page public partial class double: system. web. UI. page {protected void page_load (Object sender, eventargs e) {string type = request ["type"]. tostring (); string page = request ["page"]. tostring (); textbox1.text = "type:" + Type + "Page:" + Page ;}// list. ASPX page public partial class list: system. web. UI. page {protected void page_load (Object sender, eventargs e) {string page = request ["page"]. tostring (); textbox1.text = "page number" + Page ;}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.