URL rewrite - web.config error - asp.net

I am getting the following error when i run my .aspx page.
Error Code0x8007000d
The configuration section 'rewrite' cannot be read because it is missing a section declaration
I have a simple v.aspx page which has the following code:
Response.Write(Request("q"))
My hosting server as IIS 7 installed with URL rewrite feature enabled (that's what they claim)
My web.config file has the following lines under :
Note: The node has blue squiggly lines under it
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
I have searched stackoverflow but did not find a solution.
May be someone found a solution.
TIA

Make sure your <rewrite> is enclosed in the <system.webServer></system.webServer> section.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="v.aspx?q={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Install the URL Rewrite module http://www.iis.net/download/URLRewrite and that should be sorted. It fixed my problem

The rewrite section in system.webServer is supported in IIS7, but not IIS6. The error is likely caused by deploying this site to a server that's only running IIS6.

Related

After hosting angular application on iis server direct url is not working it or page refresh on enter is not working

Please find web.config code
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
whenever I enter URL ex myapp/orderform it always renders to home or give errors that file or directory does not exist.

Changing the URL Extension

I had developed a Web application in Asp.net. When am using the Application over IIS, the file extension as.aspx is visible. Is it possible to hide it (or) rename it....Thankx in advance.
For .NET framework 4.0+, try the following rule in web.config (inside <system.webServer>):
The first will redirect URLs using the old format, to remove the .aspx extensions. You should of course update your links as well - eventually you won't need this.
The second rule rewrites URLs internally to add .aspx behind the scenes.
<rewrite>
<rules>
<rule name="RedirectOldFormat" enabled="true" stopProcessing="true">
<match url="(.*)\.aspx" />
<action type="Redirect" url="{R:1}" />
</rule>
<rule name="InternallyAddAspx" enabled="true">
<match url=".*" negate="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{URL}" pattern="(.*)\.(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="{R:0}.aspx" />
</rule>
</rules>
</rewrite>
For .NET Framework 3.5 or earlier, you can accomplish this using routing. Try the following solution:
http://www.codedigest.com/Articles/ASPNET/294_Search_Engine_Friendly_URLs_Using_Routing_in_ASPNet_35.aspx

redirect issue on webconfig file

please check sfveinaesthetics.com/index.php opens but http://sfveinaesthetics.com/ dont.. its a wordpress site in iis7 server.
inner pages work http://sfveinaesthetics.com/about-us/ fine..
Please get a me solution asap.. web config is like
<system.webServer>
<rewrite>
<rules>
<rule name="Main Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Not sure if it's causing the problem but the default rewrite rule for Wordpress does not include the /{R:0} part in the rewrite action. Normally it's:
<action type="Rewrite" url="index.php" />

URL rewriting in ASP.NET turning http://example.com/abcd into http://example.com/page.aspx?id=abcd

I have a problem in my web forms ASP.NET app where I would like to rewrite a url from
http://example.com/abcd
into
http://example.com/page.aspx?id=abcd
the abcd part will be unique and I cant create a folder for it
I want the users to always see the http://example.com/abcd url
would the solution be the same in Windows Azure?
Can somebody please help me with some hints?
Thank You!
In your web.config, in the system.webServer section put something like this:
<!-- This has been added to support url rewriting for ... -->
<rewrite>
<rules>
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^Page\.aspx$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^id=([a-zA-Z]+)$" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" />
</rule>
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^([a-zA-Z]+)$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="Page.aspx?id={R:1}" />
</rule>
</rules>
</rewrite>
Please note that I have copied from the config we have in a production site and modified a little bit... needs testing.
The config should work when you have only words ([a-zA-Z]+), change the pattern to make it work for numbers.
hope it helps

An alternative way to rewriting URLs than the Rewrite URL graphic interface in IIS 7?

Is there any way to do it, without the user interface?
I mean a non user interface way, something like a config file hosted in my web site, or some kind of alternative ?
Thank you very much!
YES, absolutely.
Your URL Rewrite rules should be stored in web.config file (unless it is explicitly forbidden which means they will be stored in IIS main config file -- for security and performance purposes, I guess).
Here is an example of such web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="SeeOther" />
</rule>
<rule name="CatchAll" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/catchall.php?page={REQUEST_URI}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Resources