Serverside JQuery code

Posted by ramadesai108-25302 under jQuery on 2/4/2014 | Points: 10 | Views : 964 | Status : [Member] | Replies : 3
How can I do this?

$("#stor").click(function (e) {
@if(Request.IsAuthenticated)
{
if(User.Identity.Name == "me@mine.com")
{
e.preventDefaule = true;
}
}
});




Responses

Posted by: Sravan661 on: 2/5/2014 [Member] Bronze | Points: 25

Up
0
Down
Hi,
Probably
 User.Identity.Name 
would give you only the name of the authenticated user it doesn't include domain name "@mine.com".

you can't retreive those values in javascript, you can do only in view.
If you want them to be used in javascript take hidden control, assign value to that control and use it in javascript
Hope it helps you


Revert if you have any issues

Please follow the below links
http://stackoverflow.com/questions/802073/asp-net-mvc-how-to-apply-role-based-or-authentication-based-view-rendering
http://stackoverflow.com/questions/5666270/asp-net-mvc-check-if-user-is-authorized-from-javascript


sravan

ramadesai108-25302, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhukiran345 on: 2/5/2014 [Member] Starter | Points: 25

Up
0
Down
Hi,
Once try in this code. Hope it may solve ur issue

if(<%HttpContext.Current.User.Identity.Name %> == "me@mine.com") 
{
// Do Something
return false;
}


Regards,
Prabhu Kiran B

Thanks,
Prabhu Kiran Bommareddy

ramadesai108-25302, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: kgovindarao523-21772 on: 2/5/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Try Like this.
This Will Work Fine.
Please Mark as Answer If you got it.
$(documet).ready(function(){
$("#stor").click(function (e) {
var name = '@User.Identity.Name'
var bIsAuth='@Request.IsAuthenticated'

if(bIsAuth=='True')
{
if(user == "me@mine.com")
{
e.preventDefaule = true;
}
}
});
});


Thank you,
Govind

ramadesai108-25302, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response