Friday, 14 November 2014

How to Find the Javascript has enabled or not?

How to Find the Javascript has enabled or not?

For security concern, many users like to disable JavaScript in their web browser, and it raise a big problem in many website which depends on JavaScript to function well. The easy and simple solution is using the HTML “noscript” tag to display different content if JavaScript is disabled.
See following full “noscript” example :
  1. If JavaScript is disabled : Display warning message and hide the entire content with CSS.
  2. If JavaScript is enabled : Fine, do nothing.
<html>
<head></head>
<body>
<h1>noscript example</h1>
<noscript>
        <h3>JavaScript is disabled! Why you want to do so?
        Please enable JavaScript in your web browser!</h3>

        <style type="text/css">
               #main-content { display:none; }
        </style>
</noscript>

<div id="main-content">
        <h3>Welcome, JavaScript user, i like web browser with JavaScript enabled!</h3>
</div>

</body>
</html>


Handle Turn on/off JavaScript in ASP.NET MVC Web Application

Handle Turn on/off JavaScript in ASP.NET MVC Web Application
Preface
Depending on what your ASP.NET MVC Web application is supposed to do, it might be necessary that the client’s browser has JavaScript support enabled.
If this is not the case, maybe you want to make sure the user will be informed and cannot use the application.
And because there is no JavaScript available, this has to be done in a non-script way.
Use The noscript-Tag & Redirect
To handle all this without any script is quite simple. HTML offers the noscript tag.
Inside the noscript area, one can add whatever HTML code is required.
Since I want the user to be redirected to another page, I will use meta http-equiv="refresh" content="0;…" to redirect the user to the page explaining that JavaScript is required to use my application.
Add It To The Layout Page
To make sure the user will be redirected independent which page should be opened, I add the noscsript area to the _Layout.cshtml page.
And because I do use a meta tag, the code is placed into the head area to avoid warnings that meta elements cannot be nested inside the body element.
In case you use different layout pages in your application, you should put the redirection code into a partial view and add this to all of your layout pages. If there is the need to change the redirection, there will be only one place that needs to be changed.
NoJScript Controller And View
I do have a ASP.NET MVC application, so want to redirect to an appropriate controller when JavaScript is disabled, not to a HTML page.
Accordingly, I add the NoJScript controller with an Index view to my project and redirect the user to /NoJScript. The view is used to inform the user that JavaScript support is required and can contain all non-script elements that are needed.
It is important that this view does not use the layout page itself. Otherwise there will be an endless redirection loop, because when the view is opened, the browser detects there is no JavaScript enabled, and again redirects to this view, and so forth.
Access Restrictions
In case you restrict access to your application by setting the AuthorizeAttribute either to your controller or by adding
filters.Add(new System.Web.Mvc.AuthorizeAttribute());
to the App_Start/FilterConfig.cs, remember to set the AllowAnonymousAttribute to the Index method of the NoJScript controller. Otherwise, the browser is hooked in an endless loop, switching between the login page and the JavaScript required page.
Putting It Together
Here are all changes listed.
In the _Layout.cshtml page, this section is added to the head element:
<head>
<noscript>
  <meta http-equiv="refresh" content="0;url=/NoJScript" />
</noscript>
<head>
The NoJScript controller is really simple:
public class NoJScriptController : Controller
{
  //
  // GET: /NoJScript/
  [AllowAnonymous]
  public ActionResult Index()
  {
    return View();
  }
}
And the view should contain a little bit more information than this sample:
@{
  ViewBag.Title = "JavaScript required";
  Layout = null; // <= Important!
}

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>@ViewBag.Title - My MVC App</title>

  @Styles.Render("~/Content/css")
  @Scripts.Render("~/bundles/modernizr")

</head>
<body>
 To use this application JavaScript is required.
</body>


Wednesday, 29 October 2014

How to Delete all the Tables and Stored Procedures in Sql Server 2008

How to delete or drop all tables from a SQL Server database using just a SQL query.


The following SQL will delete all the tables and their associated information from a database.

USE [database]
EXEC sp_MSforeachtable @command1 = "DROP TABLE ?"
The only downside to this is that you cannot perform a rollback, so you need to make sure this is what you want to do. Otherwise, that’s all there is to it. Just run this in a New Query Window in SQL Server Management Studio (SSMS) and you’re done.


Sql Scripts - Delete all Tables, Procedures, Views and Functions

Friday, August 20, 2010SQL Server T-SQL
In a shared environment you typically don't have access to delete your database, and recreate it for fresh installs of your product.
I managed to find these scripts which should help you clean out your database.
Use at your own risk.

Delete All Tables

--Delete All Keys

DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
WHILE (@@FETCH_STATUS = 0)
BEGIN
Exec SP_EXECUTESQL @Sql
FETCH NEXT FROM @Cursor INTO @Sql
END
CLOSE @Cursor DEALLOCATE @Cursor
GO
EXEC sp_MSForEachTable 'DROP TABLE ?'
GO

Delete All Stored Procedures

declare @procName varchar(500)
declare cur cursor
  for select [name] from sys.objects where type = 'p'
open cur

fetch next from cur into @procName
    while @@fetch_status = 0
    begin
          if @procName <> 'DeleteAllProcedures'
                exec('drop procedure ' + @procName)
                fetch next from cur into @procName
    end

close cur
deallocate cur

Delete All Views

declare @procName varchar(500)
declare cur cursor
  for select [name] from sys.objects where type = 'v'
open cur

fetch next from cur into @procName
    while @@fetch_status = 0
    begin
                exec('drop view ' + @procName)
                fetch next from cur into @procName
    end
close cur
deallocate cur

Delete All Functions

declare @procName varchar(500)
declare cur cursor
  for select [name] from sys.objects where type = 'fn'
open cur

fetch next from cur into @procName
    while @@fetch_status = 0
    begin
                exec('drop function ' + @procName)
                fetch next from cur into @procName
    end

close cur
deallocate cur


Delete All SP

DECLARE @sql NVARCHAR(MAX) = N''; SELECT @sql += N'DROP PROCEDURE dbo.' + QUOTENAME(name) + '; ' FROM sys.procedures WHERE name LIKE N'sp[_]%' AND SCHEMA_NAME(schema_id) = N'dbo'; EXEC sp_executesql @sql;