为什么要点两次button以后Session值才有效?
//btn
private void Button1_Click(object sender, System.EventArgs e)
{
Session[ "UserName "]= "abc ";
Page.Response.Redirect( "http://localhost/test/welcome.aspx);
}
//httpmodule
namespace test
{
public class UserAuthorizationModule : IHttpModule
{
#region IHttpModule 成员
public void Init(HttpApplication context)
{
context.AcquireRequestState += new EventHandler(context_AcquireRequestState);
}
void context_AcquireRequestState(object sender, EventArgs e)
{
HttpApplication application = (HttpApplication)sender;
if (application.Context.Session[ "UserName "] == null || application.Context.Session[ "UserName "].ToString().Trim() == " ")
{
string requestUrl = application.Request.Url.ToString();
string requestPage = requestUrl.Substring(requestUrl.LastIndexOf( '/ ') + 1);
if (requestPage != "login.aspx ")
application.Server.Transfer( "login.aspx ");
}
}
public void Dispose()
{ }