【发布时间】:2016-06-20 06:27:19
【问题描述】:
我想从我的网络应用程序 URL 中删除“.aspx”。我也使用网络服务。
如果我使用以下代码,Web 服务将无法正常工作。
全球.asax
protected void Application_BeginRequest(object sender, EventArgs e)
{
String WebsiteURL = Request.Url.ToString();
String[] SplitedURL = WebsiteURL.Split('/');
String[] Temp = SplitedURL[SplitedURL.Length - 1].Split('.');
// This is for aspx page
if (!WebsiteURL.Contains(".aspx") && Temp.Length == 1)
{
if (!string.IsNullOrEmpty(Temp[0].Trim()))
Context.RewritePath(Temp[0] + ".aspx");
}
}
例如:-
实际页面是 DEFAULT.aspx,但我想在地址栏中显示 DEFAULT。所以我使用 Global.asax 来删除(.aspx)。它工作正常。但 Web 服务不工作(Default.asmx)
【问题讨论】:
-
我会考虑为 IIS 使用
URLRewrite模块。不一定是最容易使用的,但非常强大,我相信你会做你想做的事
标签: c# asp.net web-services web-config global-asax