2
Answers

How to URL rewrite in asp.net using Web.config file ?

Raja

Raja

8y
261
1
I had used <rewrite> </rewrite> section in web config file.but show the Error Unrecognized configuration section rewrite.
Answers (2)
0
Raja

Raja

NA 1.7k 45.3k 8y
This is Web.config Code
~~~~~~~~~~~~~~~~~~~~
 
 
 
<configuration>
  <connectionStrings>
    <add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
    </authentication>
    <membership>
      <providers>
        <clear/>
        <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
      </providers>
    </membership>
    <profile>
      <providers>
        <clear/>
        <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
      </providers>
    </profile>
    <roleManager enabled="false">
      <providers>
        <clear/>
        <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
        <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
      </providers>
    </roleManager>
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
  <rewrite>
    <rules>
      <rule name="Fail Bad request">
        <match url=".*"/>
        <conditions>
          <add input="{HTTP_HOST}" pattern="localhost" negate="true"/>
        </conditions>
        <action types="AbortRequest"/>

      </rule>
      <rule name="Redirect From Blog">
        <match url="^blog/([_0-9a-z-]+)/([0-9]+)" />
        <action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found"/>

      </rule>
      <rule name="Rewrite to article.aspx">
        <match url="^article/([0-9]+)/([_0-9a-z-]+)" />
        <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}"/>
        </rule>
      </rules>
  </rewrite>
</configuration>
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 8y
Please put the urlrewrite tag in proper place(proper tag). Provide the code how you are writing in web.config file..