Run a Unsafe code in an WebApplication or WebService

Last post 01-29-2008 12:42 PM by kirchi. 1 replies.

Sort Posts:

  • Run a Unsafe code in an WebApplication or WebService

    01-29-2008, 5:52 AM
    • Member
      point Member
    • Rajesh N
    • Member since 01-24-2008, 4:55 AM
    • Posts 3

    Does anybody know how to run an Unsafe code in an WebApplication or WebService...

    Reply...

    Thank You....

  • Re: Run a Unsafe code in an WebApplication or WebService

    01-29-2008, 12:42 PM
    • Contributor
      2,422 point Contributor
    • kirchi
    • Member since 03-07-2007, 2:47 AM
    • Posts 328

    What do you mean by "Unsafe" ?

    Do you mean the code that should be protected with role-based security ?

    If so - yes this is possible, - for example consider the following webservice that returns some string about status of the user:

    [WebMethod]
            public string IsAuthenticated()
            {
                if (User.Identity.IsAuthenticated)
                {
                    // you can also use User.Identity.Name
                    string userName = System.Web.Security.Membership.GetUser().UserName;
                    string[] roles = System.Web.Security.Roles.GetRolesForUser(userName); string allRoles = "";
                    foreach(string role in roles)
                        allRoles = String.Concat(allRoles, ", ", role);
                    return String.Format(
                        "Yes, user is authenticated, username: {0}; roles:{1}",
                        userName,
                        allRoles
                        );
                }
                else
                    return
    "No - user is not authenticated";
              
            }

     

    PS. I think I misunderstood the question - there is actually a detailed description of "unsafe" code for .NET, so I am sorry :)

    anyway I am not deleting the text above.

    My blog: http://blog.devarchive.net
    My samples: http://devarchive.net
Page 1 of 1 (2 items)