It is the process of identifying “who” the end-user is when they visit a website.
What is Authorization?
It is the process of figuring out whether the authenticated user has permissions to access a particular page/resource or to perform some action.
How to Set Authentication & Authorization in Web.config?
....
....
....
How to obtaining the Logged-in Username via Code?
protected void Page_Load(object sender, EventArgs e)
{
lblUserName.Text = "Welcome : " + GetUserWithOutDomain();
Session["UserID"] = GetUserWithOutDomain();
}
private String GetUserWithOutDomain()
{
if (HttpContext.Current.User.Identity.Name.IndexOf("\\") > 0)
{
return HttpContext.Current.User.Identity.Name.Substring(User.Identity.Name.IndexOf("\\") + 1);
}
else
return User.Identity.Name;
}
If a user not logged in via "Home" page redirect to Home.
protected void Page_Load(object sender, EventArgs e)
{
if(Session["UserID"] == null || Convert.ToString(Session["UserID"]) == String.Empty)
{
Response.Redirect("Home.aspx");
}
}
How to deploy in IIS ?
1. Open the IIS manager ( Start -> Run -> "inetmgr")
2. Right click "Web sites" select "New -> web site".
3. Click the "next" button in the web site creation wizard.
4. Enter the description in Description Box.
5. Set the TCP port and click next button .
6. Map the web site path and uncheck the "anonymous access"
7. Select the necessary permission for the site.
8. Click Next & Finished button
9. Browse the newly created page.
In this way we can avoid the user login page in Intranet ASP.net web applications.
No comments:
Post a Comment