RewritePath不会更改浏览器URL

时间:2015-06-11 03:30:28

标签: asp.net-mvc redirect

在我的Global.asax.cs中,我有以下简单的代码:

phyl=aggregate(abundance ~ phyla+species+color+time, dat, sum)
phyl=phyl[with(phyl,order(phyla,species,time)),]
wide <- reshape(phyl, idvar = c("phyla","species","color"),
          timevar = "time", direction = "wide")
wide[is.na(wide)]<-0
wide

res1=as.matrix(wide[,-c(1:3)],ncol=dim(wide[,-c(1:3)])[2])
colnames(res1)=
unlist(strsplit(colnames(res1), ".", fixed = TRUE))[seq(2,length(colnames(res1))*2,by=2)]
rownames(res1)=wide$species

barplot(res1,col=wide$color,beside = F,legend.text=T,args.legend=
          list(x = "top",bty="n",cex=.6,ncol=2))

上面的代码导致重定向到&#34; newControler / newAction&#34;呈现正确的视图,但浏览器中显示的URL仍然是&#34; / oldControler / oldAction&#34;。

如果有任何帮助,我会在应用RewritePath后检查HttpContext.Current.Request中的属性,并且所有这些属性,即FilePath,Path,ApplicationPath,URL等都正确显示为&#34; newControler / newAction&#34;,但RawUrl除外,它仍显示为&#34; / oldControler / oldAction&#34;。

关于如何修复它的任何想法?

2 个答案:

答案 0 :(得分:2)

这就是RewritePath的工作原理,它不会更改浏览器地址栏中的URL,并且通常在旧网址比新网址更友好时使用。

如果您还想更改浏览器地址栏中的网址,可以尝试

HttpContext.Current.Response.Redirect("/newControler/newAction");

或者如果您还想将HTTP 301响应代码返回到浏览器

HttpContext.Current.Response.RedirectPermanent("/newControler/newAction");

答案 1 :(得分:0)

您可以尝试:

HttpContext.Current.Response.RedirectLocation("/newControler/newAction");