可以使用 ISAPI 筛选器在 IIS Web 服务器级别实现 URL 重写,也可以使用 HTTP 模块或 HTTP 处理程序在
ASP.NET 级别实现 URL 重写。本文重点介绍如何使用 ASP.NET 实现 URL 重写,因此我们将不对使用 ISAPI 筛选器实现
URL 重写的细节进行深入探讨。但是,有大量的第三方 ISAPI 筛选器可用于 URL 重写,例如:
ISAPI
Rewrite
IIS Rewrite
PageXChanger
还有许多其他的筛选器!
通过 System.Web.HttpContext
类的 RewritePath()
方法,可以在 ASP.NET 级别实现 URL 重写。HttpContext
类包含有关特定 HTTP 请求的 HTTP 特定信息。对于 ASP.NET 引擎收到的每个请求,均为该请求创建一个 HttpContext
实例。此类具有如下属性:Request
和 Response
,提供对传入请求和传出响应的访问;Application
和 Session
,提供对应用程序和会话变量的访问;User
,提供有关通过了身份验证的用户的信息;其他相关属性。
使用 RewritePath()
方法可以接受单个字符串作为要使用的新路径。HttpContext
类的 RewritePath(string)
方法在内部对 Request
对象的 Path
属性和 QueryString
属性进行更新。除了 RewritePath( ......
1.//弹出对话框.点击转向指定页面
Response.Write(" <script>window.alrt('该会员没有提交申请,请重新提交!') </script>"); Response.Write(" <script>window.loation='http://www.cnblogs.com/kevin1031" target="_blank">http://www.cnblogs.com/kevin1031' </script>");
2.//弹出对话框
Response.Write("<script language="javascript">alrt('产品添加成功!') </script>");
3.//删除文件
string filename ="20059595157517.jpg"; pub.util.DeleteFile(HttpContext.Current.Server.MapPath("../file") +filename);
4.// 绑定下拉列表框datalistSystem.Data.DataView dv=conn.Exec_ex("select -1 as code,'请选择经营模式' as content from dealin union select code,content from dealin"); this.dealincode.DataSource=dv; this.dealincode.DataTextField="content"; this.dealincode.DataValueField="code"; this.dealincode.DataBind(); this.dealincode.Items.FindByValue(dv[0]["dealincode"].ToString ()).Selected=true;
5.//时间去秒显示<%# System.DateTime.Parse(DataBinder.Ev ......
今天在开发中,遇到了一个问题:
在Header中有一个搜索输入框,搜索按钮是Button控件,在“资讯文章搜索”用户自定义控件中也用到了Button控件。
将焦点停在“资讯标题或内容”输入框中,回车,但是相应的是Header中输入框内容。
原因:回车执行的就是你页面上的第一个submit button。解决方法:(以下以资讯搜索输入框为例)
1、js:
----------------------------------------------------------------------------
/* 回车后执行按钮 */
function SubmitKeyClick(button){
if (event.keyCode == 13){
event.keyCode = 9;
event.returnValue = false;
document.all[button].click();
}
}
function checkinputbox(){
var charBag = "[^`~@#$%^&/\'|*]";
var searchkey = document.getElemen ......
现在很多的站点都是基于JQueryUI、ExtJS等等界面库开发的,可以说前台使用了大量的脚本及静态页面,而后台往往只做为请求页面数据来用,那么合理的利用反射,通过传递指令(或动作)的参数,调用页面的相关方法,便可以减少很多的代码量。
1、所有的页面都继承于一个基类BasePage
2、在BasePage类中OnLoad事件增加反射的代码
3、页面中增加相应的方法
string action = Request.QueryString["action"];
if (action != null)
{
Type t = this.GetType();
string result = (string)t.InvokeMember(action, BindingFlags.Instance | BindingFlags.Public | BindingFlags.InvokeMethod, null, this, null);
Response.Write(result);
Response.Flush();
Response.End();
}
例如,请求的地址:http://www.test.com/test.aspx?action=GetOperList
那么,只需要在test.aspx页面中有相应的 private string GetOperList() 方法,便能反射执行,返回相应的数据。
看起来有点像MVC框架中的Controller ^_^ ......
asp,asp.net,php,jsp下的301转向代码
使用.htaccess文件来进行301重定向。
如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以下几行:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://blog.csdn.net/huwei2003"
Response.End
%>
php 301转向代码
在 index.php 的最顶部加入以下几行:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://blog.csdn.net/huwei2003");
exit();
?>
asp.net 301转向代码
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://blog.csdn.net/huwei2003");
}
</script> ......
asp,asp.net,php,jsp下的301转向代码
使用.htaccess文件来进行301重定向。
如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以下几行:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://blog.csdn.net/huwei2003"
Response.End
%>
php 301转向代码
在 index.php 的最顶部加入以下几行:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://blog.csdn.net/huwei2003");
exit();
?>
asp.net 301转向代码
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://blog.csdn.net/huwei2003");
}
</script> ......
asp,asp.net,php,jsp下的301转向代码
使用.htaccess文件来进行301重定向。
如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以下几行:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://blog.csdn.net/huwei2003"
Response.End
%>
php 301转向代码
在 index.php 的最顶部加入以下几行:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://blog.csdn.net/huwei2003");
exit();
?>
asp.net 301转向代码
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://blog.csdn.net/huwei2003");
}
</script> ......
asp,asp.net,php,jsp下的301转向代码
使用.htaccess文件来进行301重定向。
如果空间不支持.htaccess文件,那么我们还可以通过php/asp代码来进行301重定向。
为了将搜索引擎的记录更新到现在的域名上面,做了几个301重定向的东东,给大家分享一下.
asp 301转向代码
在 index.asp 或 default.asp 的最顶部加入以下几行:
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://blog.csdn.net/huwei2003"
Response.End
%>
php 301转向代码
在 index.php 的最顶部加入以下几行:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://blog.csdn.net/huwei2003");
exit();
?>
asp.net 301转向代码
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.StatusCode = 301;
HttpContext.Current.Response.Status = "301 Moved Permanently";
HttpContext.Current.Response.AddHeader("Location", "http://blog.csdn.net/huwei2003");
}
</script> ......
Asp.net日期字符串格式化显示--DateTime.ToString()用法详解
我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34
如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢?
这里将要用到:DateTime.ToString的方法(String, IFormatProvider)
示例:
using System;
using System.Globalization;
String format="D";
DateTime date=DataTime.Now;
Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));
结果输出
Thursday, June 16, 2006
在这里列出了参数format格式详细用法
=======================
格式字符 关联属性/说明
d ShortDatePattern
D LongDatePattern
f 完整日期和时间(长日期和短时间)
F FullDateTimePattern(长日期和长时间)
g 常规(短日期和短时间)
G 常规(短日期和长时间)
m、M MonthDayPattern
r、R RFC1123Pattern
s 使用当地时间的 SortableDateTimePattern(基于 ISO 8601)
t ShortTimePattern
T LongTimePattern
u UniversalSortableDateTimePattern 用于显示通用时间的格式
U 使用通用时间的完整日期和时间(长日期和长时间)
......