http模块无法获取正确的页面url

发布于 2024-12-12 08:13:29 字数 791 浏览 0 评论 0原文

嗨,我有一个非常菜鸟的问题要问。我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哑剧 2024-12-19 08:13:29

您没有得到“错误”的网址。用户的浏览器只是对不同的资源发出不同的请求。您的 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文