简体   繁体   中英

Redirect /folder to /mypage.aspx on ASP.NET and IIS 6

I am trying to set up a shorter url for the users to use in their marketing material (eg mydomain.com/jobs points to mydomain.com/employment.aspx). The biggest reason for this is that we are close to launching our new site in which /employment.aspx will no longer work. In the new site I have /jobs working, but I can't figure out how to change it on our old site. I am using IIS 6 and ASP.NET 3.5.

All of the options I have tried, there is already code in place that does work. I am not sure what is happening or what is going wrong.

  1. system.web/urlMappings <add url="~/jobs" mappedUrl="~/employment.aspx" /> - Worked on my PC, didn't work on server.
  2. system.web/urlMappings <add url="~/jobs/default.aspx" mappedUrl="~/employment.aspx" /> - /jobs/default.aspx worked, but /jobs did not.
  3. configuration/urlrewritingnet <add name="RewriteJobs" virualUrl="~/jobs" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/employment.aspx" ignoreCase="true" /> <add name="RewriteJobs2" virualUrl="~/jobs/default.aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/employment.aspx" ignoreCase="true" /> - Neither work
  4. I seen reference to using global.asax in the Application_BeginRequest method, but that didn't work either.

Can anyone point me in the right direction of what I might be doing wrong?

You might consider using Helicon Isapi rewrite for it, because as I remember there are some problems on setuping rewriting module on IIS 6. On the other hand I'm not excited with helicon. Just an option to try anyway.

Easiest way to do that without messing with any settings or plugins is to actually create that directory and put a file inside. You can have an empty default.aspx with the following contents:

<%@ Page Language="C#" %>

<script type="text/C#" runat="server">
void Page_Load(object sender, System.EventArgs e) {
    Response.Redirect("~/employment.aspx");
}
</script>

Make sure IIS treats default.aspx as a default page for this directory.

Or if you want a 301 instead of a 302, go through the process of setting those headers manually, since Response.RedirectPermanent isn't available until .NET 4.

This isn't the most "correct" way, and it would become a mess if you tried to do too many of these, but it's a quick fix that would work great temporarily.

Maybe this would work for you, a IIS fix:

http://www.iis.net/downloads/microsoft/url-rewrite

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM