使用ASP.NET实现Friendly URL的最简单方法
2007-05-10 19:23
1031 查看
这大概是最简单的方法。只要2步。
在Global.asax中加入:
void Application_BeginRequest(Object sender, EventArgs e)
...{
string strCurrentPath;
string strBasePath;
string strCustomPath;
strCurrentPath = Request.AppRelativeCurrentExecutionFilePath.Substring(2).ToLower();
strBasePath = Request.ApplicationPath;
if (strCurrentPath != string.Empty && !strCurrentPath.Contains("."))
...{
strCustomPath = strBasePath + "/Load.aspx?page=" + strCurrentPath;
// rewrite the URL
Context.RewritePath(strCustomPath);
}
else if (strCurrentPath == string.Empty)
Context.RewritePath(strBasePath + "/Default.aspx"); // by default
else
...{
Context.RewritePath(strBasePath + "/" + strCurrentPath);
}
}
IIS Application Configuration 设置中的 Application Mapping加入Extension: * Executable Path:和aps.net一样。这样做可以防止IIS来报错404。所有的事情都由asp.net来解决。接下来就可以慢慢编写Load.aspx的内容罗。
在Global.asax中加入:
void Application_BeginRequest(Object sender, EventArgs e)
...{
string strCurrentPath;
string strBasePath;
string strCustomPath;
strCurrentPath = Request.AppRelativeCurrentExecutionFilePath.Substring(2).ToLower();
strBasePath = Request.ApplicationPath;
if (strCurrentPath != string.Empty && !strCurrentPath.Contains("."))
...{
strCustomPath = strBasePath + "/Load.aspx?page=" + strCurrentPath;
// rewrite the URL
Context.RewritePath(strCustomPath);
}
else if (strCurrentPath == string.Empty)
Context.RewritePath(strBasePath + "/Default.aspx"); // by default
else
...{
Context.RewritePath(strBasePath + "/" + strCurrentPath);
}
}
IIS Application Configuration 设置中的 Application Mapping加入Extension: * Executable Path:和aps.net一样。这样做可以防止IIS来报错404。所有的事情都由asp.net来解决。接下来就可以慢慢编写Load.aspx的内容罗。
相关文章推荐
- Asp.Net使用POST方法最简单的实现
- Asp.Net使用POST方法最简单的实现
- Asp.Net使用POST方法最简单的实现
- Asp.Net使用POST方法最简单的实现
- Asp.Net使用POST方法最简单的实现
- ASP.Net MVC_DotNetZip简单使用方法,解决文件压缩的问题
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- Asp.net中使用javaScript实现前后台方法的相互调用
- ASP.NET使用Cookie简单实现记住登陆状态功能
- ASP.NET jQuery 食谱11 (通过使用jQuery validation插件简单实现用户登录页面验证功能)
- 在ASP.Net 中使用实现windows登陆的方法. (轉自tainkai的專欄.http://blog.csdn.net/tainkai)
- ASP.NET使用确认对话框得简单方法
- ASP.NET 计划任务实现方法(不使用外接程序,.net内部机制实现)
- asp.net简单实现页面换肤的方法
- 在 ASP.NET 中实现不同角色的用户使用不同登录界面的方法
- ADO.NET .net core2.0添加json文件并转化成类注入控制器使用 简单了解 iTextSharp实现HTML to PDF ASP.NET MVC 中 Autofac依赖注入DI 控制反转IOC 了解一下 C# AutoMapper 了解一下
- asp.net中Datalist使用数字分页的实现方法
- ASP.NET jQuery 随笔 使用allValidator插件简单实现客户端验证功能