Note that there are some explanatory texts on larger screens.

plurals
  1. POUse of Location tag in authorization
    primarykey
    data
    text
    <p>I have a <strong>web.config</strong> file through which I am trying to provide role based security to my application using <strong>location</strong> tags. I have read many articles and move to the result, that <strong>location</strong> tags provide the access to the limited folders for the authorized users like in my web config I have a folder "<strong>HRpages</strong>" which only allow access to the users who have roles as "<strong>HR</strong>". But I am not clear how I use this in my code file(<strong>Login.aspx.cs</strong>) for authorization.</p> <p><strong>NOTE:</strong> Right now <strong>"Login.aspx.cs"</strong> is not redirecting me to the "<strong>WelcomeHR.aspx</strong>" page. Don't know why.</p> <p><em><strong>Web.Config</em></strong> </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;configuration&gt; &lt;system.web&gt; &lt;compilation debug="true" targetFramework="4.0" /&gt; &lt;authentication mode="Forms"&gt; &lt;forms loginUrl="Login.aspx" defaultUrl="WelcomePage.aspx"&gt; &lt;/forms&gt; &lt;/authentication&gt; &lt;authorization&gt; &lt;deny users="?" /&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;location path="HRpages"&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow roles="HR" /&gt; &lt;deny users="*" /&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;/location&gt; &lt;location path="AdminPages"&gt; &lt;system.web&gt; &lt;authorization&gt; &lt;allow roles="Admin" /&gt; &lt;deny users="*" /&gt; &lt;/authorization&gt; &lt;/system.web&gt; &lt;/location&gt; &lt;system.webServer&gt; &lt;defaultDocument&gt; &lt;files&gt; &lt;add value="AddTwoNumbers.asmx" /&gt; &lt;/files&gt; &lt;/defaultDocument&gt; &lt;/system.webServer&gt; &lt;/configuration&gt; </code></pre> <p><em><strong>Login.aspx.cs</em></strong></p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Security; namespace WebServiceExample { public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text.Trim() == "ABC" &amp;&amp; TextBox2.Text.Trim() == "Gupta" &amp;&amp; TextBox3.Text == "HR") { String returnUrl1; // the login is successful if (Request.QueryString["ReturnUrl"] == null) { returnUrl1 = "HRPages/WelcomeHR.aspx"; } //login not unsuccessful else { returnUrl1 = Request.QueryString["ReturnUrl"]; } Response.Redirect(returnUrl1); } } } } </code></pre> <p><strong>Any Help????</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload