webfrom架构设置页面在框架内打开,防止非法越权操作

第一步:打开Global文件,找到Application_BeginRequest事件。

第二步:添加非法越权操作代码,限制内容页只能在框架内打开,代码如下:

HttpApplication app = (HttpApplication)sender;
string requestPath = app.Context.Request.Path; //获得请求的URL,例:WebSite1Login.6html
string fileName = System.IO.Path.GetFileName(requestPath); //获得路径中的文件名,Login.6html
var urlReferrer = app.Context.Request.UrlReferrer;
if (urlReferrer == null && requestPath !="/")
{
if (!fileName.Contains("Login") && !fileName.Contains("default")
&& !fileName.Contains("index"))
{
//string newPath = "~adminhomeindex.aspx";
//app.Context.RewritePath(newPath, false);
Response.Redirect("/admin/home/index.aspx");
}
}

原文地址:https://www.cnblogs.com/redfull/p/10572998.html