以前发过一个.NET上传文件的方法的,不过那个方法中对文件类型的判断只是对后缀名来进行判断的,这样假如我把一个txt文本文件的后缀名改为jpg了也可以上传,这样无意中就造成了安全问题。
刚刚从网上找了个方法,试验了一下,是能够辨认出正确的文件类型的,如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class niunantest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string str = FileUpload1.PostedFile.ContentType;
Response.Write("文件类型:"+str);
string filename = "";
FileExtension[] fe = { FileExtension.GIF, FileExtension.JPG, FileExtension.PNG };
if (FileValidation.IsAllowedExtension(FileUpload1, fe))
{
str ......
其实所谓的伪静态页面,就是指的URL重写,在ASP.NET中实现非常简单
首先你要在你的项目里引用两个DLL:
ActionlessForm.dll
URLRewriter.dll
真正实现重写的是 URLRewriter.dll 但是如果你要实现分页,那么必须使用这个ActionlessForm .dll
首先在web.config里写
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>
<!-- 下面是配置重写URL规则 -->
<RewriterConfig>
<Rules>
<RewriterRul ......
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["login"] != null)
{
this.Button1.Attributes.Add("onclick", "if(!confirm('确实要订购吗?')) return false;");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script>alert('当前购物车中,没有商品');</script>"); &nb ......
今天在csdn上看到一篇博客,是讲解关于'asp.net中解决页面刷新后字体等变大问题的',看了一下,感觉写的不是很详细。那么,我利用他的实例来具体了解一下:
原文:
protected void Button1_Click(object sender, EventArgs e)
{
//Page.RegisterStartupScript("ServiceManHistoryButtonClick", "<script>alert('当前购物车中,没有商品');</script>");
//或下面都可,上面第一个参数随便起,不要重复.
Response.Write("<script>alert('当前购物车中,没有商品');</script>");
Response.Write(" <script>document.location=document.location; </script>");
& ......
using System;
using System.Web;
namespace pub.mo
{
public class js
{
private js() { }
private static string scr_j1 = "<mce:script type=\"text/javascript\"><!--
";
private static string scr_j2 = "
// --></mce:script>";
/// <summary>
/// 输入js并停止运行
/// </summary>
/// <param name="str"></param>
public static void write_js(string str)
{
HttpContext.Current.Response.Write(config.j1);
HttpContext.Current.Response.Write(scr_j1);
HttpContext.Current.Response.Write(str);
HttpContext.Current.Response.Write(scr_j2);
HttpContext.Current.Response.Write(config.j2);
HttpContext.Current.Response.End();
}
/// <summary>
/// 输入js,无Response.End()
/// </summary>
/// <param name="str"></param>
public static vo ......
using System;
using System.Web;
namespace pub.mo
{
public class js
{
private js() { }
private static string scr_j1 = "<mce:script type=\"text/javascript\"><!--
";
private static string scr_j2 = "
// --></mce:script>";
/// <summary>
/// 输入js并停止运行
/// </summary>
/// <param name="str"></param>
public static void write_js(string str)
{
HttpContext.Current.Response.Write(config.j1);
HttpContext.Current.Response.Write(scr_j1);
HttpContext.Current.Response.Write(str);
HttpContext.Current.Response.Write(scr_j2);
HttpContext.Current.Response.Write(config.j2);
HttpContext.Current.Response.End();
}
/// <summary>
/// 输入js,无Response.End()
/// </summary>
/// <param name="str"></param>
public static vo ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace pub.mo
{
public class request
{
private request() { }
/// <summary>
/// 获取session
/// </summary>
/// <param name="_session_name"></param>
/// <returns></returns>
public static string session(string _session_name)
{
object obj = HttpContext.Current.Session[_session_name];
return obj == null ? config.empty : obj.ToString();
}
/// <summary>
/// 得到Request.QueryString
/// </summary>
/// <param name="_str"></param>
/// <returns></returns>
public static string querystring(string _str)
{
string s = HttpContext.Current.Request.QueryString[_str];
return s == null ? config.empty : s;
}
/// <summary> ......
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace pub.mo
{
public class request
{
private request() { }
/// <summary>
/// 获取session
/// </summary>
/// <param name="_session_name"></param>
/// <returns></returns>
public static string session(string _session_name)
{
object obj = HttpContext.Current.Session[_session_name];
return obj == null ? config.empty : obj.ToString();
}
/// <summary>
/// 得到Request.QueryString
/// </summary>
/// <param name="_str"></param>
/// <returns></returns>
public static string querystring(string _str)
{
string s = HttpContext.Current.Request.QueryString[_str];
return s == null ? config.empty : s;
}
/// <summary> ......