0

Completely new to C#, so please be patient with me.

I have an application with 2 links. 1 link for anyone to see, 1 for only certain people to see. The code and files and everything are the exact same, the only difference is that if the link contains a certain string in it, it hides certain areas of the page using jquery.

So, I have a lot of different cshtml pages and I don't want to have to rewrite the logic I use to check the username and redirect or not in each page.

I know how to get the username, check if the name is in the 'special list array' and redirect to the appropriate website if not... Just don't know how I can do this efficiently. If 1 person gets added to the array, currently I have to update the array on every page.

Is there a place I can put the function and just call it on each cshtml page?

string userName = Environment.UserName;  // System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string[] arr1 = new string[] { "one", "two", "three" };
bool inArray = false;
for (int i = 0; i < arr1.Length; i++)
{
    if (userName == arr1[i]){
        inArray = true;
    }
}
if(inArray)
{
    Response.Redirect("link1");
}
else
{
    Response.Redirect("link2");
}
5
  • You might want to add the asp.net tag.
    – Adam Szabo
    Apr 18, 2013 at 8:16
  • 1
    you might want to look into authorization and authentication nerddinnerbook.s3.amazonaws.com/Part9.htm Apr 18, 2013 at 8:17
  • Did you use C# login feature or ur create it on ur own? Apr 18, 2013 at 8:17
  • it's an intranet site, so don't want to require a login. there's only a small number of users that should see the special link so was just trying to find a quick way to do this. Apr 18, 2013 at 8:22
  • could you show us your current special array code - its not clear if this is server side or client side code. Apr 18, 2013 at 8:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.