Routing an ASP page to a Action in ASP.NET MVC - asp.net

I am recreating a site from VB .NET to MVC 4 ASP.NET. In the old project there is a system that sends an email to a user and within that email there is a hyperlink that can direct the user to view the specific task. I want to make all of the old emails work with the new recreated site. Here is an example of the hyperlink in the old system:
http://pppweb/accounting/ap/default.asp?etaskid=32698
And here is an example of what a hyperlink looks on the new system.
http://pppweb/accounting/ap/ApIssues/Task/32698
So I was thinking i could create a default.asp page in my MVC project and try and have it parse the taskID out. I am not exactly sure the best way to go about doing this?

I would advise against adding a classic .asp (not .aspx?) page in your project, since I'm not even sure there is a way to do that. You can, assuming you are running IIS7, map the url:
http://pppweb/accounting/ap/default.asp
to be handled by MVC by adding the following line to your web.config file:
<configuration>
...
<system.webServer>
...
<handlers>
...
<add name="aspnet htm" path="account/api/default.asp" verb="*" type="System.Web.Mvc.MvcHttpHandler" preCondition="integratedMode" />
Then, add a route for that url and requests should resolve to the normal route parameters you specify. From that point, you should be able to access etaskid from the query string easily enough.
Edit:
Alternatively, if the url matters a lot to you, you can specify a redirect rule from the old format url to the new one by using UrlRewrite module (also an IIS 7 feature). You can read about it here: http://www.iis.net/downloads/microsoft/url-rewrite

Related

Redirect ASP pages to a new URL

Our old website was built using ASP and now we are using Wordpress (IIS) utilizing a sub-directory. All of the old ASP files are still in the root directory and I'd like to redirect all of these file extensions to our new Wordpress site because the old ASP files are causing 404 errors.
I'm having a real difficult time figuring out what to put in my web.config file so all the old ASP pages are redirected to our new home page.
Thanks
The best option is to use the URL Rewriting extension for IIS ( http://www.iis.net/downloads/microsoft/url-rewrite ) which can also perform regex-based redirections. Create a new rule that matches (.+)\.asp and redirects as appropriate.
I don't know if you just want to do a 'dumb' redirect from all .asp-URIs to your WordPress root, or if you want to intelligently redirect users from the old .asp pages to their new WordPress equivalents (this is a good idea as it means search engine results and previous links won't be broken, I'm sure you can imagine how frustrating it is to follow a link that doesn't go where the user expects).
Thanks everyone for your suggestions, but because I don't have access to the server, my only solution was to work with the web.config file. I simply added the following code and everything now works:
<directoryBrowse enabled="true" />
<httpRedirect enabled="true" exactDestination="true" httpResponseStatus="Found">
<add wildcard="*.asp" destination="/" />
</httpRedirect>

Redirect a user when he or she tries to navigate to a page in ASP.NET website

Is it possible to re-direct a request for a page 'XYZ.aspx' to 'ABC.aspx', without writing any code? We are using ASP.Net 4.0 with IIS 7.5.
The idea is that we want to remove XYZ.aspx page from our website, and if users still use old bookmarks that point to XYZ.aspx, then we want them to be taken to ABC.aspx in an automated manner.
there seems to be a few ways, link should hopefully help you out.
http://www.trainsignal.com/blog/iis7-redirect-windows-server-2008
you can forward the user through web.config file or you can do it through IIS too. but I I were you I would use web.config. in shared hosting u cannot touch IIS.
I found the answer. One needs to use the following in web config, and that's it.
<location path="XYZ.aspx">
<system.webServer>
<httpRedirect enabled="true" destination="http://localhost/mysite/ABC.aspx" httpResponseStatus="Permanent" />
</system.webServer>
UPDATE : This will also work if any query string parameters are passed to the page XYZ.aspx.

ASP.NET redirect rule for .cfm file

I have a DotNetNuke application where I am migrating all my old web sites all together under portals.
As users are storing old sites URLs into bookmarks, I need to write redirect rules so they can get properly on new page.
Now, at one point I stuck because I am unable to write rule.
My condition is
URL A
http://www.mydomain.com.cn/auto.cfm?myurl=domain/notice_article.cfm
Should redirect to
http://www.mynewdomain.com/home.aspx
I have implemented this using redirectMaps.
e.g.
<rewriteMap name="MyRedirectMap_Entire">
<add key="whttp://www.mydomain.com.cn/auto.cfm?myurl=domain/notice_article.cfm" value="http://www.mynewdomain.com/home.aspx" />
</rewriteMap>
Adding this properly under web.config file, I able to redirect properly.

Redirecting in ASP.NET

I recently deployed a new version of an ASP.NET website. This site is built from scratch so urls that worked on the old site do not work on the new one. I've discovered that some of the old pages are requested quite a lot, so I'd like to redirect users trying to get those pages to corresponding new ones.
Let's say the old site had this page:
www.mysite.com/mypage.aspx
And the new site has this corresponding page:
www.mysite.com/pages/mypage.aspx
What is a good (the best) way to redirect requests for the old page to the new page?
My first though was using url mappings in web.config, but that doesn't work for me. The reason is that no real redirect occurs so the right page is shown but the url is not updated in the browser, which leads to the problem that all my relative links get messed up.
Of course I could just recreate the old ASPX pages on the new site and redirect from those, but I don't want to have this "garbage files" in my web project.
Preferably I'd like a solution where I could do all this redirecting in one place. That's what I liked about using url mappings in web.config, but that solution had other problems as mentioned.
Any suggestions?
There are 2 things that come to my mind right now.
A find & replace which is cumbersome yet effective. This is probably
or
You can use the html base tag
http://www.w3schools.com/tags/tag_base.asp
http://www.htmlcodetutorial.com/linking/_BASE.html
But keep in mind that this actually changes ALL the url's (including img urls) in a page.
If it's just a few pages, you could register one single handler for each of the urls and then in the handler redirect to the correct page.
For example
<add name="GetMemberPortrait.aspx_*" path="GetMemberPortrait.aspx" verb="*" type="ExposureRoom.Web.GetMemberPortrait" preCondition="integratedMode"/>
In this web.config file entry (in the handlers section) you see that for the path"GetMemberPortrait.aspx" a specific handler has been registered. That is for that specific "aspx" page the hander specified is instantiated.
The handler can just be a .cs file that implements the IHttpHandler interface. And you can use the same handler to handle all such cases.
For each url, you'll need an entry but you can use the same handler. so for example if you have 3 urls that need redirection called
1. page1.aspx
2. page2.aspx
3. page3.aspx
<add name="page1.aspx_*" path="page1.aspx" verb="*" type="SomeNameSpace.RedirectorHandler" preCondition="integratedMode"/>
<add name="page2.aspx_*" path="page2.aspx" verb="*" type="SomeNameSpace.RedirectorHandler" preCondition="integratedMode"/>
<add name="page3.aspx_*" path="page3.aspx" verb="*" type="SomeNameSpace.RedirectorHandler" preCondition="integratedMode"/>
In your handler, you'll get all of the request parameters as well so you can use those to forward on to the redirected page.
Using the URL Rewrite module for IIS, see http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

Why isn't my IHttpHandler being called?

I'm trying to get a custom handler to work for a specific URL (or set of URLs) in ASP.NET 3.5.
The handler doesn't actually do anything significant yet - it just logs the request. I can post the code if anyone things it's relevant, but I really don't think it's being called at all. (In particular, for normal exceptions I get a custom error page and logging... here I'm just getting the vanilla IIS 404.)
Here's the relevant bit of the web.config file:
<system.web>
<httpHandlers>
<add verb="GET,POST" path="*.robot" validate="false"
type="CSharpInDepth.Wave.RobotHandler, CSharpInDepth"/>
</httpHandlers>
</system.web>
(Obviously there's other stuff in that section too, but I don't think it's relevant.)
Locally, running under the dev server, it works fine. On my real box, I always get a 404. Everything under the web site directory itself is the same (replicated via svn). That includes the bin directory containing CSharpInDepth.dll, which I've verified contains CSharpInDepth.Wave.RobotHandler.
I try to fetch http://csharpindepth.com/foo.robot and just get a 404.
I've tried with and without the assembly name, specific URLs or wildcarded ones... nothing's working.
I'm sure I've just missed some simple flag somewhere in the IIS configuration, but I'm blowed if I can find it...
EDIT: It's IIS version 6. Attempting to add *.robot to the ISAPI filter now...
Well if the hosting box is IIS7 in integrated pipeline you need to add it into the other bit of the config:
<system.webmodules>
....
<modules>
<add name="RobotHandler" type="CSharpInDepth.Wave.RobotHandler, CSharpInDepth"/>
</modules>
....
</system.webmodules>
If it's IIS6 then you'll need to map *.robots to the ASP.NET ISAPI DLL.
(For the non-Skeets you do this as follows)
Open up IIS admin.
Right click on
the Web site you want to configure
and select Properties form the
context menu. This will display the
Web Site Properties dialog.
Select
the Home Directory tab and click the
Configuration button. This will
display the Application
Configuration dialog box.
Click
Add.
Select the aspnet_isapi.dll
from the .NET framework directory,
the extension you want mapped and
either All Verbs, or just the ones
you want to map.
Click ok.
Jon,
You'll have to configure the IIS script mappings to pass *.robot to aspnet_isapi.dll.

Resources