Thursday, October 25, 2018

Change Fonts and Colors in Visual Studio

Change the background color of your code editor

Change the Color Theme of the IDE

On the menu bar, choose Tools, Options.



In the options list, choose Environment, General.



In the Color theme list, choose either the default Blue theme, Dark or Light.

To change the font and size of all text in the IDE

1.On the menu bar, choose Tools, Options.

2.In the options list, choose Environment, Fonts and Colors.

3.In the Show settings for list, choose Environment Font.

4.In the Font list, choose a font.

5.In the Size list, choose a text size, and then choose the OK button.

Tuesday, October 23, 2018

JQuery: how to replace all between certain characters?

Syntax:
string.replace(/abc.+xyz/,"abc"+newString+"xyz");


Input value :
 var inputString="(10.00%)(20.00%)(10.00%)Testing Value";

 var   Output =inputString.replace(/\(.*%\)/ig,"");

Result value :
    Testing Value


SQL replace all characters between two strings

How can I use replace statement in SQL query to replace/remove all the text inside the square bracket and the square bracket itself. I have many similar text like that with square bracket in my database, can I use regular expression or something similar?

Solution :
declare @str varchar(100)
select @str='This is Sql testing Text [23/10/2018 12:23 - admin]'
select stuff(@str,patindex('%(%',replace(@str,'[','(')),LEN(@str),'')

Result :  This is testing Text 

Tuesday, January 23, 2018

Redirect to login page if Idle Timeout is 10mins

MVC

The Following javascript file put in Layout Page(Views/Shared/_layout.cshtml ) on MVC page.

<script type="text/javascript">
        rootUrl = '@Url.Content("~/")';
        var t;
        window.onload = resetTimer;
        document.onkeypress = resetTimer;

        function logout() {
           // alert("You are now logged out.")
            // location.href = 'Logoff.php'
            window.location.href = '@Url.Action("Login", "Register")';

        }

        function resetTimer() {

            clearTimeout(t);
           // t = setTimeout(logout, 60000) //logs out in 1 min
         t = setTimeout(logout, 600000) //logs out in 10 min
        }


    </script>
================
Web Page(ASP.NET)

 The Following javascript file put on Master Page.(MasterPage.master) on ASP.NET Site

 <script type="text/javascript">
 var t;
        window.onload = resetTimer;
        document.onkeypress = resetTimer;

        function logout() {
            // alert("You are now logged out.")
            // location.href = 'Logoff.php'
            //window.location.origin : you'll get http://sub.domain.com *****
            window.location.href = window.location.origin+"/Account/login";

        }

        function resetTimer() {
            clearTimeout(t);
         //   t = setTimeout(logout, 60000) //logs out in 1 min
             t = setTimeout(logout, 600000) //logs out in 10 min

        }
    </script>

If no activity for 15 minutes, display an alert on web page, and then either continue or logout

This displays a jQuery dialog after 14 minutes of inactivity. If 15 minutes passes and no activity is found to be happening within the browser it is redirected to a logout URL:

// Set timeout variables.
var timoutWarning = 840000; // Display warning in 14 Mins.
var timoutNow = 900000; // Timeout in 15 mins.
var logoutUrl = 'http://domain.com/logout.aspx'; // URL to logout page.

var warningTimer;
var timeoutTimer;

// Start timers.
function StartTimers() {
    warningTimer = setTimeout("IdleWarning()", timoutWarning);
    timeoutTimer = setTimeout("IdleTimeout()", timoutNow);
}

// Reset timers.
function ResetTimers() {
    clearTimeout(warningTimer);
    clearTimeout(timeoutTimer);
    StartTimers();
    $("#timeout").dialog('close');
}

// Show idle timeout warning dialog.
function IdleWarning() {
    $("#timeout").dialog({
        modal: true
    });
}

// Logout the user.
function IdleTimeout() {
    window.location = logoutUrl;

}


Add onload to your body tag calling StartTimers(). You can also add an onmousemove to the body tag which calls ResetTimer() so that as long as there is activity on the page a timeout is not triggered. If no mouse activity is seen on the page the dialog is displayed if movement is detected the dialog is closed and the timers reset.

<body onload="StartTimers();" onmousemove="ResetTimers();">
And the div used for the jQuery dialog:

<div id="timeout">
    <h1>Session About To Timeout</h1>
    <p>You will be automatically logged out in 1 minute.<br />
    To remain logged in move your mouse over this window.
</div>


Of course you can modify it to fit your needs and wants such as adding a button click which calls ResetTimers() if you dont want it reset when a mouse is moved over the browser but this should give you a starting point.

Monday, January 22, 2018

How to fix This site can't be reached error





Right click on your MVC Project. Go to Properties. Go to the Web tab.
Change the port number in the Project Url. Example. 
localhost:50645
Changing the bold number, 50645, to anything else will change the port the site runs under.
Press the 
Create Virtual Directory button to complete the process.


1.Image shows the web tab of an MVC Project 


2. rename Applicationhost configuration file



Mixed Content: The page at xxx was loaded over HTTPS, but requested an insecure

 Mixed Content: The page at ' https ://www.test.com/signup.aspx' was loaded over HTTPS, but requested an insecure script ' http ...