我如何使用 Global.asax 并为其实现处理程序?
我有一个 Global.ascx 并且编写了一个简单的 url writer 模块:
void Application_BeginRequest(对象发送者,EventArgs e) { 尝试 { 字符串 strPath = Context.Request.Url.AbsoluteUri; string[]sections = strPath.Split('/'); int len =sections.Length; string strExtention =sections[len - 1].Split('.')[1]; if (strExtention.ToLower().TrimEnd().Equals("xml")) { if (sections[len - 2].Equals("ATM")) Context.RewritePath("~/Include/XML Files/Orders/TMP/" +sections[len - 1]); 别的 Context.RewritePath("~/Include/XML Files/Orders/" +sections[len - 1]); } } 抓住 { } }
它在本地工作,但在主机中不起作用,我如何为此实现处理程序?
Server.Transfer 也不起作用。
I have a Global.ascx and I wrote a simple url writer module :
void Application_BeginRequest(object sender, EventArgs e) { try { string strPath = Context.Request.Url.AbsoluteUri; string[] sections = strPath.Split('/'); int len = sections.Length; string strExtention = sections[len - 1].Split('.')[1]; if (strExtention.ToLower().TrimEnd().Equals("xml")) { if (sections[len - 2].Equals("ATM")) Context.RewritePath("~/Include/XML Files/Orders/TMP/" + sections[len - 1]); else Context.RewritePath("~/Include/XML Files/Orders/" + sections[len - 1]); } } catch { } }
it works locally but it dosen't work in the host how I can implement handler for this ?
Server.Transfer doesn't work also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您沿着模块的路线走是正确的。但是,使用
Response.Redirect()
代替Context.RewritePath()
,这只是向浏览器返回一条 3xx 消息,该消息会将其请求重定向到新 URL。无论在哪里实施,这都应该有效。You are correct with going down the route of a module. However instead of
Context.RewritePath()
useResponse.Redirect()
, this simply returns a 3xx message to the browser which will redirect its request to the new URL. This should work wherever it's implemented.