I understand how routing works in asp.net web from.
I want to prevent users to access urls like 'Default.aspx'. So when a user tried access url like 'Default.aspx' it redirected to 'Default'.
For example i tried this:
routes.MapPageRoute("", "Default.aspx", "~/Default");
but it does not work! Is there another way?
Please excuse me for poor and bad English.
Webforms or MVC? It's not clear from your question and tagging....
Where have you added this code in your app? It needs to be in application_start() in global.ascx for a WebForms app.
Alternatively, You can try re-writing the url in the web.config (in system.webServer):
<rewrite>
<rules>
<rule name="MyRuleName" stopProcessing="true">
<match url="^default$" ignoreCase="true" />
<action type="Rewrite" url="/default.aspx" />
</rule>
</rules>
</rewrite>
Related
I've implemented Friendly URLs in a Webform project but it allows a user to go to either the root of the website or /default. I really want to get rid of the /default option by having it always just route to the root. I've tried using
routes.MapPageRoute("", "Default", "~/")
but that doesn't seem to effect anything.
Anyone now the proper way to accomplish this?
The easiest way to achieve this will be through IIS not in code. It will create a 301 redirect from requests to default.aspx to the root.
<system.webServer>
<rewrite>
<rules>
<rule name="default page" stopProcessing="true">
<match url="^default\.aspx$" />
<action type="Redirect" url="{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
I can't seem to find an answer but I would like to remove an old redirect from the web config file of an IIS server.
Here is the redirect:
<rule name="Redirect Old Returns Page" stopProcessing="true">
<match url="^returns$" />
<action type="Redirect" url="https://{HTTP_HOST}/warranties" redirectType="Permanent" />
</rule>
I would now like that /returns page to be available, but when I remove that redirect from the config and restart the application pool it still redirects.
Anyone know what's going on? Never had to remove a redirect before and thought it would be simple.
Thanks
I've got two websites.
XX.XX.XX.XXX:5917 which is a webforms website
And
XX.XX.XX.XXX:5916 which is an mvc website.
Both websites on the same IIS 7 server. I can navigate each website, login, etc.
However, when a user goes to XX.XX.XX.XXX:5917/Report I want the content from XX.XX.XX.XXX:5916/Report to be served up, but the url to remain XX.XX.XX.XXX:5917/Report.
To do this, I'm trying to set up a reverse proxy on the 5917 site to serve up content from 5916.
When I have a redirect rule in place, I can click a link in 5917 to Reports and it will take me to 5916/Reports. This works, but changes the address bar. When I use the Rewrite rule option, absolutely nothing discernible happens. If I screw up the end url in the action bracket then the page will break, so I know it's at least evaluating the rule.
Here is the 'working' redirect rule:
<rule name="Reverse Proxy to Reports" stopProcessing="true">
<match url="\bReport\b" />
<action type="Redirect" url="http://XX.XX.XX.XXX:5916/{R:0}" />
</rule>
Am I missing anything? Where do I go from here?
Try adding this on your XX.XX.XX.XXX:5917 WebForms web.config:
<system.webServer>
...
<rewrite>
...
<rules>
<rule name="ReverseProxyInboundRuleForReports" stopProcessing="true">
<match url="(Report/.*)" />
<action type="Rewrite" url="http://localhost:5916/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
You might need 'Application Request Routing' extension on IIS for it to work though. If so then you can get it from this link:
http://www.iis.net/downloads/microsoft/application-request-routing
You can also read more about the technique on this link:
http://weblogs.asp.net/owscott/creating-a-reverse-proxy-with-url-rewrite-for-iis
Good luck!
I'm currently researching how to implement URL Rewriting and was wondering if someone could help shed some light.
Our current url structure is the following..
http://example.com/products.cfm?id=1234
http://example.com/recipes.cfm?id=6789
I would like to configure IIS so that URLs can be rewritten to the following (or similar)
http://example.com/products/1234/product-title-here
http://example.com/recipes/6789/yummy-recipe-ever
How would I go about doing this?
Read through this walk through. The example comes close to what you want (replaced aspx with cfm).
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.cfm?id={R:1}&title={R:2}" />
</rule>
</rules>
</rewrite>
Look into Coldbox there is a rewrite.ini and IS7 web.config included
http://wiki.coldbox.org/wiki/URLMappings.cfm
The Coldbox blog shared this link
http://blog.coldbox.org/blog/coldbox-and-url-rewrites-with-iis-7
I want to re-direct from an exact URL request to a new site within that domain.
I need to re-direct requests from
www.example.com/site111/default.aspx?configX.xml
(this site uses a different config file to load content)
to
www.example.com/site222/default.aspx
Issue is that I need to leave access www.example.com.au/site111/default.aspx
so I cannot just to a http re-direct as there is no file called default.aspx?configX.xml
I think I need to use a URL rewrite re-direct
Can someone help me with the syntax for the web config I cannot get it to work
0 module installed and have used the above syntax and it still doesn't work,
If I use the test feature on the module it says that the string matches,
very confused,
the actual webconfig section is here
<rewrite>
<rules>
<rule name="Redirect2" stopProcessing="true">
<match url="\/nrmmaps\/default.aspx\?config=nrmproject.xml$" />
<action type="Redirect" url="/nrmproject/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
and the old link is
http://se.nrmspace.com.au/nrmmaps/default.aspx?config=nrmproject.xml
and I want it to re-direct to
http://se.nrmspace.com.au/nrmproject/default.aspx
Do you have any idea why this is not working?
I believe you need to install the IIS rewrite module which can be found here:
http://www.iis.net/downloads/microsoft/url-rewrite
After you do that, you can add a rewrite section with a redirect rule in your web.config like so:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url="\/site111\/default.aspx\?configX.xml$" />
<action type="Redirect" url="/site222/default.aspx" redirectType="Permanent"/>
</rule>
</rules>
</rewrite>
</system.webServer>
Hope this helps