紧急求助 页面跳转问题

zhuwenli 2011-04-08 03:22:17
我有一个域名:www.abc.cn
我现在想实现:www.abc.cn/baidu 时跳转到指定的页面
因该如何实现?
我现在是这样做的
在Global.asax 中
void Application_BeginRequest(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
string strurlData = HttpContext.Current.Request.RawUrl;
if (strurlData != null && strurlData != "")
{

string[] strs = strurlData.Split('/');
bool flag = false;
for (int i=0;i<strs.Length ;i++ )
{
if (strs[i].ToUpper() == "baidu")
{
flag = true;
break;
}
}
if(flag)
HttpContext.Current.Response.Redirect("http://www.baidu.com");


在开发环境中运行时可以的,但在IIS中就不行了
我用的Visual 2008+windows2003 请问各位大哥大姐如何解决。
...全文
590 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhuwenli 2011-04-10
  • 打赏
  • 举报
回复
我不想用javascript该如何呢
我调试过了再开发环境中式没问题的可以实现功能
但部署到iis中就不行了不知道是什么原因
zhuwenli 2011-04-10
  • 打赏
  • 举报
回复
应该是这样的代码我写错了
void Application_BeginRequest(object sender, EventArgs e)
{
//throw new Exception("The method or operation is not implemented.");
string strurlData = HttpContext.Current.Request.RawUrl;
if (strurlData != null && strurlData != "")
{

string[] strs = strurlData.Split('/');
bool flag = false;
for (int i=0;i<strs.Length ;i++ )
{
if (strs[i].ToUpper() == "BAIDU")
{
flag = true;
break;
}
}
if(flag)
HttpContext.Current.Response.Redirect("http://www.baidu.com");
子夜__ 2011-04-10
  • 打赏
  • 举报
回复
protected void Application_BeginRequest(object sender, EventArgs e)
{
//原来的url
string url = HttpContext.Current.Request.RawUrl;
//经过处理的新的url
string newUrl = ""
HttpContext.Current.RewritePath(newUrl);
}

//DEMO

string url = HttpContext.Current.Request.RawUrl;
string pattern = @"(\S+)(article/)+(\S+)(/read.aspx)(\S*)";
string newUrl = "";

if (System.Text.RegularExpressions.Regex.IsMatch(url, pattern, System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.IgnoreCase))
{
newUrl = System.Text.RegularExpressions.Regex.Replace(url, pattern, "$1Article.aspx?articleId=$3");
HttpContext.Current.RewritePath(newUrl);
}
dsfmt 2011-04-10
  • 打赏
  • 举报
回复
代码放在Session_Start里看看。
haa17 2011-04-08
  • 打赏
  • 举报
回复

<script type="text/javascript">
Jump();
function Jump()
{
var url=document.URL.toLowerCase();
if(url.indexOf("a1.iwom-trends.com")>=0 || url.indexOf("a2.iwom-trends.com")>=0 )
location.href="Login.aspx?loginout=t&adminlogin=t";
else if(url.indexOf("b1.iwom-trends.com")>=0 || url.indexOf("b2.iwom-trends.com")>=0)
location.href="Login.aspx?loginout=t&trackeradminlogin=t";
else if(url.indexOf("c1.iwom-trends.com")>=0 || url.indexOf("c2.iwom-trends.com")>=0)
location.href="Login.aspx?loginout=t";
}
</script>

直接页面加载调用js就可以。
yanru900821 2011-04-08
  • 打赏
  • 举报
回复
if (strs[i].ToUpper() == "baidu")
这句好像有点问题
zhuwenli 2011-04-08
  • 打赏
  • 举报
回复
在开发环境中是可以运行的不用调试的
  • 打赏
  • 举报
回复
断点调试一下呢!应该是路径的问题!

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧