Click here to Skip to main content
15,512,502 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: GridView behaving Strangely in an asp.net web page. Pin
Richard Deeming16-Feb-16 8:27
mveRichard Deeming16-Feb-16 8:27 
GeneralRe: GridView behaving Strangely in an asp.net web page. Pin
Member 1221350616-Feb-16 8:33
Member 1221350616-Feb-16 8:33 
QuestionHow to create a language translator in asp.net using c#? Pin
Raja Ganapathy16-Feb-16 3:15
Raja Ganapathy16-Feb-16 3:15 
AnswerRe: How to create a language translator in asp.net using c#? Pin
Richard MacCutchan16-Feb-16 4:15
mveRichard MacCutchan16-Feb-16 4:15 
Questionhave a problem in custom control with javascript Pin
Member 1207470715-Feb-16 19:57
Member 1207470715-Feb-16 19:57 
SuggestionRe: have a problem in custom control with javascript Pin
Kornfeld Eliyahu Peter15-Feb-16 21:06
professionalKornfeld Eliyahu Peter15-Feb-16 21:06 
QuestionTelerik TreeList Child Level Items are not retrievable by using FindItemByKeyValue method Pin
indian14312-Feb-16 17:53
indian14312-Feb-16 17:53 
Questionproper use of System.Web.HttpContext.Current.User Pin
jkirkerx12-Feb-16 13:56
professionaljkirkerx12-Feb-16 13:56 
I didn't want to use the Owin security, yet wanted to use a custom Attribute [Security] for my Controller action results to validate the user before doing anything. Currently I'm using Sessions to store the Name.

But when I run the Attribute, the System.Web.HttpContext.Current.User Name is empty.

I'm not sure if I implemented the construction of the System.Web.HttpContext.Current.User wrong, of if the value won't persist because I placed in another class. Or perhaps I'm suppose to store something in the database for this.

This is everything I have. I call the code below on a successful login.
// Add the Validated User to the Role for Security Purposes
String[] newRoles = { "Administrator", "Customer" };
GenericIdentity newIdentity = new GenericIdentity(model.AccountName);
GenericPrincipal newPrincipal = new GenericPrincipal(newIdentity, newRoles);                       
System.Web.HttpContext.Current.User = newPrincipal;   
My custom Attribute, that I wrote in another class Dll.
[AttributeUsageAttribute(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class SecurityCheckAttribute : ActionFilterAttribute, IActionFilter
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string accountName = HttpContext.Current.User.Identity.Name;
            if (accountName != null)
            {
                bool result = ef_website_accounts.verify_accountName(accountName);
                if (false == result)
                {

                    filterContext.Result = new RedirectToRouteResult(
                        new RouteValueDictionary{
                        { "controller", "Admin" },
                        { "action", "Logout" } 
                    });
                }
            }
            else
            {
                filterContext.Result = new RedirectToRouteResult(
                new RouteValueDictionary{
                    { "controller", "Admin" },
                    { "action", "Logout" }
                });

            }
            base.OnActionExecuting(filterContext);
        }

    }

I'd rather build a mini Owin in where I can store user information in an object and call it anywhere on the back end, but this is a start.

The one that came with the program was too complex for my needs, And if it keeps changing, I didn't want to deal with more code updates.
AnswerRe: proper use of System.Web.HttpContext.Current.User [Not Solved but I get it now] Pin
jkirkerx13-Feb-16 14:53
professionaljkirkerx13-Feb-16 14:53 
SuggestionRe: proper use of System.Web.HttpContext.Current.User [Not Solved but I get it now] Pin
Richard Deeming15-Feb-16 3:26
mveRichard Deeming15-Feb-16 3:26 
GeneralRe: proper use of System.Web.HttpContext.Current.User [Not Solved but I get it now] Pin
jkirkerx15-Feb-16 8:15
professionaljkirkerx15-Feb-16 8:15 
QuestionASP .NET Custom Validation client side code not Working Pin
Member 1218422112-Feb-16 10:24
Member 1218422112-Feb-16 10:24 
AnswerRe: ASP .NET Custom Validation client side code not Working Pin
JHizzle15-Feb-16 0:36
JHizzle15-Feb-16 0:36 
GeneralRe: ASP .NET Custom Validation client side code not Working Pin
Member 1218422115-Feb-16 5:15
Member 1218422115-Feb-16 5:15 
GeneralRe: ASP .NET Custom Validation client side code not Working Pin
JHizzle16-Feb-16 2:07
JHizzle16-Feb-16 2:07 
AnswerRe: ASP .NET Custom Validation client side code not Working Pin
Wayne Stewart_17-Feb-16 4:41
Wayne Stewart_17-Feb-16 4:41 
Questionhow to implement unit measrements using asp.net webservices Pin
Member 1231070412-Feb-16 0:41
Member 1231070412-Feb-16 0:41 
AnswerRe: how to implement unit measrements using asp.net webservices Pin
Nathan Minier12-Feb-16 2:49
professionalNathan Minier12-Feb-16 2:49 
AnswerRe: how to implement unit measrements using asp.net webservices Pin
aarif moh shaikh15-Feb-16 20:59
professionalaarif moh shaikh15-Feb-16 20:59 
QuestionAccess the Public Property of User Control in the ASP.Net web farms page Pin
indian14310-Feb-16 15:01
indian14310-Feb-16 15:01 
AnswerRe: Access the Public Property of User Control in the ASP.Net web farms page Pin
Richard Deeming11-Feb-16 1:45
mveRichard Deeming11-Feb-16 1:45 
GeneralRe: Access the Public Property of User Control in the ASP.Net web farms page Pin
indian14312-Feb-16 14:01
indian14312-Feb-16 14:01 
GeneralRe: Access the Public Property of User Control in the ASP.Net web farms page Pin
Richard Deeming15-Feb-16 2:49
mveRichard Deeming15-Feb-16 2:49 
QuestionChange attributes value of web form user control in div by using jquery Pin
koklimabc10-Feb-16 7:47
koklimabc10-Feb-16 7:47 
AnswerRe: Change attributes value of web form user control in div by using jquery Pin
ZurdoDev10-Feb-16 10:44
professionalZurdoDev10-Feb-16 10:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.