Click here to Skip to main content
15,860,861 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: GridView behaving Strangely in an asp.net web page. Pin
Richard Deeming16-Feb-16 7:27
mveRichard Deeming16-Feb-16 7:27 
GeneralRe: GridView behaving Strangely in an asp.net web page. Pin
Member 1221350616-Feb-16 7:33
Member 1221350616-Feb-16 7:33 
QuestionHow to create a language translator in asp.net using c#? Pin
Raja Ganapathy16-Feb-16 2:15
Raja Ganapathy16-Feb-16 2:15 
AnswerRe: How to create a language translator in asp.net using c#? Pin
Richard MacCutchan16-Feb-16 3:15
mveRichard MacCutchan16-Feb-16 3:15 
Questionhave a problem in custom control with javascript Pin
Member 1207470715-Feb-16 18:57
Member 1207470715-Feb-16 18:57 
SuggestionRe: have a problem in custom control with javascript Pin
Kornfeld Eliyahu Peter15-Feb-16 20:06
professionalKornfeld Eliyahu Peter15-Feb-16 20:06 
QuestionTelerik TreeList Child Level Items are not retrievable by using FindItemByKeyValue method Pin
indian14312-Feb-16 16:53
indian14312-Feb-16 16:53 
Questionproper use of System.Web.HttpContext.Current.User Pin
jkirkerx12-Feb-16 12:56
professionaljkirkerx12-Feb-16 12: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 13:53
professionaljkirkerx13-Feb-16 13:53 
SuggestionRe: proper use of System.Web.HttpContext.Current.User [Not Solved but I get it now] Pin
Richard Deeming15-Feb-16 2:26
mveRichard Deeming15-Feb-16 2:26 
GeneralRe: proper use of System.Web.HttpContext.Current.User [Not Solved but I get it now] Pin
jkirkerx15-Feb-16 7:15
professionaljkirkerx15-Feb-16 7:15 
QuestionASP .NET Custom Validation client side code not Working Pin
Member 1218422112-Feb-16 9:24
Member 1218422112-Feb-16 9:24 
AnswerRe: ASP .NET Custom Validation client side code not Working Pin
JHizzle14-Feb-16 23:36
JHizzle14-Feb-16 23:36 
GeneralRe: ASP .NET Custom Validation client side code not Working Pin
Member 1218422115-Feb-16 4:15
Member 1218422115-Feb-16 4:15 
GeneralRe: ASP .NET Custom Validation client side code not Working Pin
JHizzle16-Feb-16 1:07
JHizzle16-Feb-16 1:07 
AnswerRe: ASP .NET Custom Validation client side code not Working Pin
Wayne Stewart_17-Feb-16 3:41
Wayne Stewart_17-Feb-16 3:41 
Questionhow to implement unit measrements using asp.net webservices Pin
Member 1231070411-Feb-16 23:41
Member 1231070411-Feb-16 23:41 
AnswerRe: how to implement unit measrements using asp.net webservices Pin
Nathan Minier12-Feb-16 1:49
professionalNathan Minier12-Feb-16 1:49 
AnswerRe: how to implement unit measrements using asp.net webservices Pin
aarif moh shaikh15-Feb-16 19:59
professionalaarif moh shaikh15-Feb-16 19:59 
QuestionAccess the Public Property of User Control in the ASP.Net web farms page Pin
indian14310-Feb-16 14:01
indian14310-Feb-16 14:01 
AnswerRe: Access the Public Property of User Control in the ASP.Net web farms page Pin
Richard Deeming11-Feb-16 0:45
mveRichard Deeming11-Feb-16 0:45 
GeneralRe: Access the Public Property of User Control in the ASP.Net web farms page Pin
indian14312-Feb-16 13:01
indian14312-Feb-16 13:01 
GeneralRe: Access the Public Property of User Control in the ASP.Net web farms page Pin
Richard Deeming15-Feb-16 1:49
mveRichard Deeming15-Feb-16 1:49 
QuestionChange attributes value of web form user control in div by using jquery Pin
koklimabc10-Feb-16 6:47
koklimabc10-Feb-16 6:47 
AnswerRe: Change attributes value of web form user control in div by using jquery Pin
ZurdoDev10-Feb-16 9:44
professionalZurdoDev10-Feb-16 9: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.