At the page load I want to check Request.IsAuthenticated. How can I do it through javascript.
The code below shows how I did it in asp.net c#?
if (!Request.IsAuthenticated)
{
Response.Redirect("~/Login.aspx");
}
At the page load I want to check Request.IsAuthenticated. How can I do it through javascript.
The code below shows how I did it in asp.net c#?
if (!Request.IsAuthenticated)
{
Response.Redirect("~/Login.aspx");
}
If you are using ASP.NET MVC then you can do like following.
<script>
var isRequestAuthenticated=' @Request.IsAuthenticated';
</script>
Else if you are using normal ASP.NET Web forms
<script>
var isRequestAuthenticated='<%=Request.IsAuthenticated%>';
</script>
Now you can use that variable to check whether this request is authenticated or not.
if(isRequestAuthenticated){foo();} will execute foo() if isRequestAuthenticated == "False". I took out the single quotes and added .ToString().ToLower().This should work:
<script type="text/javascript">
function foo(){
if('@Request.IsAuthenticated' === 'True') {
// your implementation for authenticated users go here
}
else{
// your implementation for not authenticated users....
//e.g. alert('You must be logged in to do bla bla bla');
}
}
</script>