62,047
社区成员
发帖
与我相关
我的任务
分享
public partial class Global : System.Web.HttpApplication
{
void Application_BeginRequest(object sender, EventArgs e)
{
if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
{
Context.RewritePath(Request.RawUrl.ToLower().Replace(".aspx", ".html"));//Context.RewritePath不改变地址栏的url重写
}
}
//或者使用下面的代码
//void Application_AcquireRequestState(object sender, EventArgs e)
//{
// if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
// {
// Response.Redirect(Request.RawUrl.ToLower().Replace(".aspx",".html"));//用Response.Redirect可以改变地址栏进行url重定向
// }
// }
}
<%@ Application Language="C#" CodeFile="Global.asax.cs" Inherits="Global" %>
<script runat="server">
</script>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Web.Caching;
void Application_BeginRequest(object sender, EventArgs e)
{
if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
{
Context.RewritePath(Request.RawUrl.ToLower().Replace(".aspx", ".html"));//Context.RewritePath不改变地址栏的url重写
}
}
//或者使用下面的代码
//void Application_AcquireRequestState(object sender, EventArgs e)
//{
// if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
// {
// Response.Redirect(Request.RawUrl.ToLower().Replace(".aspx",".html"));//用Response.Redirect可以改变地址栏进行url重定向
// }
// }
void Application_AcquireRequestState(object sender, EventArgs e)
{
//禁止匿名用户访问Manager目录
if (Regex.IsMatch(Request.RawUrl.ToLower(), @".aspx") == true)
{
Response.Redirect(Request.RawUrl.ToLower().Replace(".aspx",".html"));//用Response.Redirect可以改变地址栏进行url重定向
//Context.RewritePath(Request.RawUrl.ToLower().Replace(".aspx", ".html"));//Context.RewritePath不改变地址栏的url重写
}
}