http模块无法获取正确的页面url
嗨,我有一个非常菜鸟的问题要问。我正在使用 http 模块来获取访问权限。假设用户是“admin”,那么他被授权查看该页面。http模块将根据页面url从数据库获取访问权限,然后http模块将确定用户是否允许访问。
这是我的示例编码:
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_AcquireRequestState1);
}
void context_AcquireRequestState1(object sender, EventArgs e)
{
try
{
string requestUrl = application.Request.AppRelativeCurrentExecutionFilePath.ToString().Trim();
//return last string of .aspx
string requestAspx = requestUrl.Substring(requestUrl.LastIndexOf('/') + 1).Trim();
}
但是 httpmodule 将运行几次。它无法正确获取 url。 例如,第一次可能会得到~/Module/Admin/Role/RoleManagementList.aspx。 然后第二次会得到错误的网址 ~/favicon.ico。有人能帮我解决这个问题吗?太感谢了
Hi i got a very noob question to ask . I am using http module to do a access right. Let say the user is 'admin' then he got authorized to view the page.The http module will get the access right from the database based on the page url, thereafter the http module will determine the user is allowed to access or not .
Here is my sample coding :
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_AcquireRequestState1);
}
void context_AcquireRequestState1(object sender, EventArgs e)
{
try
{
string requestUrl = application.Request.AppRelativeCurrentExecutionFilePath.ToString().Trim();
//return last string of .aspx
string requestAspx = requestUrl.Substring(requestUrl.LastIndexOf('/') + 1).Trim();
}
but the httpmodule will run several time. It cant get the url correctly.
For example first time it may get ~/Module/Admin/Role/RoleManagementList.aspx.
then second time will get the wrong url ~/favicon.ico.Can anyone help me solve this problem? thank you so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有得到“错误”的网址。用户的浏览器只是对不同的资源发出不同的请求。您的 http 模块将为每个 http 请求执行,这意味着除了“页面”之外的每个资源,例如网站图标(显示在浏览器 URL 中,即使您没有,有时也会请求)或图像、外部页面上引用的 .css、外部 .js 文件等(除非它们直接由 IIS 绕过 ASP.NET 堆栈提供服务)。您需要在模块中考虑所有这些 url。
根据您对部署环境的控制程度,您还可以/相反,通过让 IIS 直接为某些文件扩展名提供服务,从而使某些文件扩展名免受每次访问 asp.net 的影响。请参阅 http://msdn.microsoft.com/en-us/library/ms972953。 ASPX
You are not getting the "wrong" url. The user's browser is simply making a different request for a different resource. You http module will execute for each http request, which will mean one for each resource in addition to the "page" such as favicons (displayed in the browsers url, and sometimes requested even if you don't have one) or images, external .css, external .js files, etc. referenced on the page (unless they are directly served by IIS bypassing the ASP.NET stack). You will need to consider all of these urls in your module.
Depending on how tightly you control your deployment environment,you may also/instead be able to exempt certain file extensions from every hitting asp.net by having IIS simply serve them directly. See http://msdn.microsoft.com/en-us/library/ms972953.aspx