JG Vimalan's Blog

It is all about coding!

Force Login dialog display

 To force login dialog in your asp.net application, follow the following steps,

1. Open global.asax .cs

2. Add the Application_AuthenticateRequest event

 3. Add the following code as shown below,

//this event will get hit after verifying with the AD

 protected void Application_AuthenticateRequest(object sender, EventArgs e){

. . . //your logic here

var loggedUser = Request.ServerVariables[“Logon_User”].ToLower(); //get the logged in user… //your logic here
//now force login dialog to display

Response.AppendHeader(“WWW-Authenticate”, “Basic”); 

Response.StatusCode = 401;

Response.End();

}

December 30, 2009 Posted by | ASP.NET | Leave a comment

Authorization in Web.Config file

Authorization for users / group to view certain pages under a folder or certain pages itself can be set in web.config file as shown below,

<location path=”Admin”>
    <system.web>
      <authorization>
        <allow users=”test\user1, test\user2, test\user3″ />
        <!– Only these people can access all the files under admin folder –>
        <deny users=”*” />
      </authorization>
    </system.web>
  </location>
  <location path=”Review.aspx”>
    <system.web>
      <authorization>
        <allow roles=”test\report group” />
        <!– Only this group can access the Review page –>
        <deny users=”*” />
      </authorization>
    </system.web>
  </location>

December 16, 2009 Posted by | ASP.NET | Leave a comment