| |

VerySource

 Forgot password?
 Register
Search
View: 636|Reply: 3

Questions about IHttpModule

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-3-13 10:00:01
| Show all posts |Read mode
I made an http module today, I want to use him to judge, the login system is not,
I wrote it like this,
 public class httpModuleSession: IHttpModule, IRequiresSessionState

    {
        public void Init (HttpApplication application)
        {
            application.AcquireRequestState + = (new EventHandler (this.Application_AcquireRequestState));

        }
        private void Application_AcquireRequestState (Object source, EventArgs e)
        {
            HttpApplication application = (HttpApplication) source;
            HttpContext context = (HttpContext) application.Context;
            string url = context.Request.Url.ToString (). Substring (context.Request.Url.ToString (). LastIndexOf ('/') + 1) .ToLower ();
            if (url! = "login.aspx"&&context.Session ["UserInfo"]! = null)
            {
                context.Response.Redirect ("login.aspx");
            
            }
     
       }
        public void Dispose ()
        {
        }
    }
But it always reminds me that context.Session ["UserInfo"] does not exist. Excuse me, in which event can I capture the session? And if I write it like this
   if (url! = "login.aspx")
            {
                context.Response.Redirect ("login.aspx");
            
            }
So the picture in login.aspx doesn't show anything? Why not let me see it?
Reply

Use magic Report

2

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-8-13 18:00:01
| Show all posts
Before context.Session, is it necessary to
if(Session["UserInfo"]!=null)
{
....
}
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-13 18:15:02
| Show all posts
use
System.Web.HttpContext.Current Get Session
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-13 18:30:01
| Show all posts
HttpApplication application = (HttpApplication)source;
HttpContext context = (HttpContext)application.Context;

The context can only be used as the context of the current http request.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list