简体   繁体   English

将/ folder重定向到ASP.NET和IIS 6上的/mypage.aspx

[英]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). 我正在尝试为用户设置较短的URL,以便用户在其营销材料中使用(例如,mydomain.com/jobs指向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. 造成这种情况的最大原因是,我们即将启动/employment.aspx无法使用的新站点。 In the new site I have /jobs working, but I can't figure out how to change it on our old site. 在新站点中,我可以使用/ jobs,但是我不知道如何在旧站点上进行更改。 I am using IIS 6 and ASP.NET 3.5. 我正在使用IIS 6和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. system.web / urlMappings <add url="~/jobs" mappedUrl="~/employment.aspx" /> -在我的PC上工作,在服务器上不工作。
  2. system.web/urlMappings <add url="~/jobs/default.aspx" mappedUrl="~/employment.aspx" /> - /jobs/default.aspx worked, but /jobs did not. system.web / urlMappings <add url="~/jobs/default.aspx" mappedUrl="~/employment.aspx" /> />-/jobs/default.aspx有效,但/ jobs无效。
  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 配置/ urlrewritenet <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" /> -均<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" />
  4. I seen reference to using global.asax in the Application_BeginRequest method, but that didn't work either. 我看到了在Application_BeginRequest方法中使用global.asax引用,但这也不起作用。

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. 您可能会考虑使用Helicon Isapi重写,因为我记得在IIS 6上设置重写模块存在一些问题。另一方面,我对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: 您可以具有以下内容的空default.aspx:

<%@ 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. 确保IIS将default.aspx视为该目录的默认页面。

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. 或者,如果您想使用301而不是302,请手动设置这些标头,因为Response.RedirectPermanent在.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: 也许这对您有用,一个IIS修复程序:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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