我希望允许我的Intranet用户加载任何HTML页面。 用户只能加载以用户名开头的html页面,例如:
User: 972547J
Pages: 972537J*****.HTML
我使用了asp.NET和VB.net,我只使用972537J****.HTML
(对于这个用户)的页面的链接按钮创建了一个gridview
这些页面是保密的,那么我不希望用户手动更改链接并显示其他用户的HTML页面。
我可以拒绝用户不打开其他人的HTML页面吗?使用Web配置设置还是iis7配置? HTML页面不可编辑
答案 0 :(得分:3)
第一步是使用.html
asp.net
个文件
第二步是使用global.asax
检查文件名是否允许查看文件名。
这是一个简单的代码,属于global.asax
:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
// you may need this
HttpApplication app = (HttpApplication)sender;
// start by check if is html file
string cTheFile = HttpContext.Current.Request.Path;
string sExtentionOfThisFile = System.IO.Path.GetExtension(cTheFile);
if (sExtentionOfThisFile.Equals(".html", StringComparison.InvariantCultureIgnoreCase))
{
// check if the user is logged in
if( HttpContext.Current.User == null ||
HttpContext.Current.User.Identity == null ||
!HttpContext.Current.User.Identity.IsAuthenticated)
)
{
// redirect him where you like
}
else
{
// make the rest test here
// HttpContext.Current.User.Identity
}
}
}
处理程序的参考:
Using ASP.NET routing to serve static files
ASP.NET MVC Routing - add .html extension to routes
http://technet.microsoft.com/en-us/library/cc770990(v=ws.10).aspx