Problem with ASP.net URL - asp.net

I want to rewrite:
Test.php to Default.asp
So I use the rule:
<rewrite url="~/Test.php" to="~/default.asp" />
But that rule gives a 404.
However this rule works fine:
<rewrite url="~/default.aspx" to="~/default.asp" />
But this rule 404's:
<rewrite url="~/Test" to="~/default.asp" />
My web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<rewriter>
<rewrite url="~/Test.php" to="~/default.asp" />
</rewriter>
</configuration>

What is PHP being handled by?
Per the setup documentation you need to ensure that the PHP extension is being handled by ASP.NET. In addition, if IIS is checking to see if the file exists before handing it off to ASP.NET you'd potentially be missing this as well.
Also, based on your system.webServer addition (which isn't detailed on the module's site), can we assume Server 2008? If so, can I recommend URL Rewrite instead?

Related

Url Rewriting in asp.net doesn't work for me

I am having the below URL and code to change the URL to my custom name in URL. It doesn't return any error but the URL not change.
I want the output like this
From : Frm_AdminHome.aspx?MainPage=AdminDashboard&Type=1&Role=r0LnJW8xTBkMh3DZ3ip3Jyt2o98/krx7
To : Frm_AdminHome/
My Webconfig code is here.
Frm_AdminHome.aspx?MainPage=AdminDashboard&Type=1&Role=r0LnJW8xTBkMh3DZ3ip3Jyt2o98/krx7 //Query string will be change in every time.
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime requestValidationMode="2.0" />
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web>
<rewriter>
<rewrite url="~/Frm_AdminHome/(.+).aspx" to="~/Frm_AdminHome.aspx" />
</rewriter>
Rewrite is a process where requested url is not changed and another page is delivered. For example, when you need to call /Frm_AdminHome, but execute /Frm_AdminHome.aspx?something without changing the url then you need following rewrite rule
<rewrite url="^/Frm_AdminHome/?$" to="/Frm_AdminHome.aspx?something" processing="stop" />
If you need to change url from Frm_AdminHome.aspx?something to Frm_AdminHome/, this is called redirect and you need to use the redirect rule
<redirect url="~/Frm_AdminHome.aspx\?.*" to="~/Frm_AdminHome" />
This should redirect
From : Frm_AdminHome.aspx?MainPage=AdminDashboard&Type=1&Role=r0LnJW8xTBkMh3DZ3ip3Jyt2o98/krx7
To : Frm_AdminHome/
Refer to http://urlrewriter.net/index.php/support for more details.
If configuration above is not working and you do not see any change then it's most likely that UrlRewriter module is not active. For example, if you run in integrated pool mode you might need to add
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<!--<modules runAllManagedModulesForAllRequests="true" />-->
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter"
type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</modules>
</system.webServer>
P.S.
For IIS 7+ there is a buit-in URL Rewrite Module
P.P.S.
To get querystring or rawurl use
QueryString <%=Request.QueryString.ToString() %> <br />
RawUrl <%=Request.RawUrl %>

URL rewriting pages is showing 404 error

I am using Intelligencia URL rewriting, but those pages is not redirecting and showing error 404. While I have installed rewrite module on server. Please suggest me what is mistake I am doing. My web.config file is below..
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
</configSections>
<appSettings/>
<connectionStrings>
<add name="connStr" connectionString="Data Source=INV-DEV-SQL2K5;Initial Catalog=WidenerPortal;Persist Security Info=True;User ID=widener;Password=widener123a" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true"/>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="Windows"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
</system.web>
<rewriter>
<rewrite url="~/Article/(.+)-(.+).aspx" to="~/DynamicPage.aspx?MyTitleId=$2"/>
</rewriter>
</configuration>
First of all add Intelligencia.UrlRewriter dll reference in your
asp.net application and than below setting in your web.config file:
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
</system.web>
<rewriter>
<rewrite url="w1" to="WebForm1.aspx" />
<rewrite url="w2" to="WebForm2.aspx" />
</rewriter>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</modules>
</system.webServer>
Try it with call your page with new url like webform2.aspx as w2. It will work fine
Use this. Mode=RemoteOnly redirect when you access from another host
<customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
or visit http://urlrewriter.net/index.php/support/reference/error-handler/error-page

UrlRewriter.NET - simple rewrite rule, but how?

I have just installed the sample from Urlrewriter.net, but I can't seem to figure out
the rule for accomplishing my problem.
Very simple:
If the user is navigated to this page:
http://localhost/UrlRewriteTest/Default.aspx?PageID=33
The Url should look like:
http://localhost/UrlRewriteTest/33
or maybe
http://localhost/UrlRewriteTest/33.aspx
What am I doing wrong? Here is my web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"/>
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>
</httpModules>
<compilation targetFramework="4.0"/>
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<rewriter>
<rewrite url="~/(.+)" to="~/Default.aspx?PageID=$1"/>
</rewriter>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>
That is the first step. More ideally PageID should be passed to a database
and return the pagename instead of an ID, and the URL should end up looking
like this:
http://localhost/UrlRewriteTest/thename/
Best regards.
You can read Scott Guthrie's article about Url Rewriting # http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx.

UrlRewriting.Net not working even with a simple rewrite

I want to make URL rewriting using UrlRewriteNet module.
While I have added all the required config settings, nothing seems to take action even for simple rewrite.
web.config:
<configuration>
<configSections>
<!-- URL Rewriting.NET -->
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter" />
</configSections>
<system.web>
<httpModules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRewriteModule"/>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
<urlrewritingnet
xmlns="http://www.urlrewriting.net/schema/config/2006/07">
<rewrites>
<add name="GeneralRewrite"
virtualUrl="^~/Default.aspx"
rewriteUrlParameter="ExcludeFromClientQueryString"
destinationUrl="~/MyDefault.aspx"
ignoreCase="true"
/>
</rewrites>
</urlrewritingnet>
</configuration>
Nothing more is requires as far as I understand to just rewrite the Deafault.aspx page to MyDefault.aspx. So I would expect my URL from https://server.address/Project.SiteName/Default.aspx to simply become https://server.address/Project.SiteName/MyDefault.aspx.
I use development in my local IIS 7 Windows 7 development pc but the release production server will be IIS 6 thats why I included both configuration into the web.config.
Unfortunately, and where there is no error for any reason, checked the IIS and saw that the module is registered in Modules section but the engine never runs !
Is there something that I miss here?
make the above in following manner
<configuration>
<configSections>
<section name="urlrewritingnet"
restartOnExternalChanges="true"
requirePermission ="false"
type="UrlRewritingNet.Configuration.UrlRewriteSection,
UrlRewritingNet.UrlRewriter" />
</configSections>
</configuration>
then comes the rewriting sections to rewrite urls
<urlrewritingnet>
<rewrites>
your urls to rewite will mapped here.....
</rewrites>
</urlrewritingnet>
and finally need to http module which will listen to the requests.
<system.web>
<httpModules>
<add name="UrlRewriteModule"
type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</httpModules>
</system.web>
Except this no configuration needs to done in web.config just reference the dll (mandatory)
and .xsd file for intellisense
http://blog.vizioz.com/2009/11/add-intellisense-when-using-url.html
Open Web.config and add modules
<configuration>
<system.webserver>
<modules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
</modules>
</system.webServer>
</configuration>

URLRewriter rewrites all requests, even for images

I'm using URLRewriter, but there is a problem, it re-write all addresses, even for image URLs, for example, it shows a webpage for http://localhost/images/logo.png.
It's my web.config
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>
<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
<rewriter>
<rewrite url="~/pages/(.+)" to="~/default.aspx?pn=$1" />
</rewriter>
</configuration>
I want it re-write only .aspx files.
The url attribute in the rewrite element is a .Net regular expression, at the moment the expression you have matches anything under ~/pages/. If you only want to match .aspx files the simplest thing to do is change it to:
<rewrite url="~/pages/(.+\.aspx)" to="~/default.aspx?pn=$1" />

Resources