0%

How to load Template in Angular?

1
2
3
4
5
6
7
public class HomeController : Controller
{
public ActionResult Template(string id)
{
return PartialView(string.Format("~/Views/Home/Partials/{0}.cshtml", id));
}
}

Then, we can use following code

1
<div ng-include="'/Home/Template/Index'"></div>

I get the following error:

Script:
C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\12.0\Extensions\2q5cdx5o.qzv\TestFiles\Jasmine\v2\jasmine.js

Error: ‘null’ is not an object (evaluating ‘currentSpec.expect’) #665

I find the root cause:

1
2
3
describe("[TS]Test", function () {
expect("").toBe("");
});

I forgot to add the ‘it’ statement around my expect.

1
2
3
4
5
describe("[TS]Test", function () {
it("test",() => {
expect("").toBe("");
});
});

Use the /accepteula command-line switch to accept the licence agreement.

Or set

    HKCU\Software\Sysinternals\PsExec\EulaAccepted

to 1

Caution: if the reg key above is set to 0 (EULA was declined once) then the /accepteula will not work, you have to set the key to 1 manually (or delete it altogether).

The SessionExpireFilterAttribute action filter is then automatically called before each action to check if Session”UserName” is null. If it determines a timeout has not occurred, it allows the actual called action to execute. Otherwise, it forces a redirect to a timeout notification page, which in turn redirects to the logon page to allow the user to re-logon.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class SessionExpireFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;

// If the browser session or authentication session has expired...
if (ctx.Session["UserName"] == null || !filterContext.HttpContext.Request.IsAuthenticated)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
// For AJAX requests, we're overriding the returned JSON result with a simple string,
// indicating to the calling JavaScript code that a redirect should be performed.
filterContext.Result = new JsonResult { Data = "_LogonTimeoutRedirect_" };
}
else
{
// For round-trip posts, we're forcing a redirect to Home/TimeoutRedirect/, which
// simply displays a temporary 5 second notification that they have timed out, and
// will, in turn, redirect to the logon page.
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary {
{ "Controller", "Home" },
{ "Action", "TimeoutRedirect" }
});
}
}
base.OnActionExecuting(filterContext);
}
}

We’ll create a couple of action filters to provide cross-cutting checks for timeout scenarios. The first will normally be hit when the browser session has timed out, but will also handle if the authentication has timed out first:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class SessionAuthorizeAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
HttpContext ctx = HttpContext.Current;

// If the browser session has expired...
if (ctx.Session["UserName"] == null)
{
if (filterContext.HttpContext.Request.IsAjaxRequest())
{
// For AJAX requests, we're overriding the returned JSON result with a simple string,
// indicating to the calling JavaScript code that a redirect should be performed.
filterContext.Result = new JsonResult { Data = "_LogonTimeoutRedirect_" };
}
else
{
// For round-trip posts, we're forcing a redirect to Home/TimeoutRedirect/, which
// simply displays a temporary 5 second notification that they have timed out, and
// will, in turn, redirect to the logon page.
filterContext.Result = new RedirectToRouteResult(
new RouteValueDictionary {
{ "Controller", "Home" },
{ "Action", "TimeoutRedirect" }
});
}
}
else if (filterContext.HttpContext.Request.IsAuthenticated)
{
// Otherwise the reason we got here was because the user didn't have access rights to the
// operation, and a 403 should be returned.
filterContext.Result = new HttpStatusCodeResult(403);
}
else
{
base.HandleUnauthorizedRequest(filterContext);
}
}
}

The Timeout Warning Message Page

1
2
3
4
<meta http-equiv="refresh" content="5;url=/Account/Logon/" />
<h2>
Sorry, but your session has timed out. You'll be redirected to the Log On page in 5 seconds...
</h2>

We can register global filter

1
2
3
4
5
6
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new SessionExpireFilterAttribute());
filters.Add(new SessionAuthorizationAttribute());
}

Client-Side Calling Code Sample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
$.ajax({
url: "/MyController/MyAction",
type: 'POST',
dataType: 'json',
data: jsonData,
contentType: 'application/json; charset=utf-8',
success: function (result) {
if (checkTimeout(result)) {
// There was no timeout, so continue processing...
}
},
error: function (result) {
if (checkTimeout(result)) {
// There was no timeout, so continue processing...
}
}
});


function checkTimeout(data) {
var thereIsStillTime = true;
if (data) {
if (data.responseText) {
if ((data.responseText.indexOf("<title>Log On</title>") > -1) || (data.responseText.indexOf("<title>Object moved</title>") > -1) || (data.responseText === '"_LogonTimeoutRedirect_"')) thereIsStillTime = false;
} else {
if (data == "_Logon_") thereIsStillTime = false;
}
if (!thereIsStillTime) {
window.location.href = "/Home/TimeoutRedirect";
}
} else {
$.ajax({
url: "/Home/CheckTimeout/",
type: 'POST',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
async: false,
complete: function (result) {
thereIsStillTime = checkTimeout(result);
}
});
}
return thereIsStillTime;
}

In Web.config, we can control the session timeout

1
2
3
<system.web>
<sessionState mode="InProc" timeout="1" cookieless="UseCookies" />
</system.web>

Razor is giving me this nonsensical error:

The name ‘model’ does not exist in the current context.

The part that makes literally zero sense is that this is causing the error:

1
@model ICollection<DataSourceByActive>

I know for a fact that @model is proper Razor syntax.

So why is this happening? How can I fix it?

I think you have messed up the web.config file which lives in the Views folder.

Create a new project targeting same .NET framework and copy its Views/web.config file over top the one in your current project

This will fix your problem.

We can add following MSBuild script in your csproj file.

1
2
3
4
5
6
7
8
9
10
11
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets"
Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\$(TypeScriptToolsVersion)\Microsoft.TypeScript.targets')" />
<Target Name="CombineT1" BeforeTargets="PrepareForBuild">
<ItemGroup>
<T1TypeScriptFiles Include="$(projectDir)Scripts\t1\*.ts;" Exclude="$(projectDir)\Scripts\**\*.d.ts;" />
</ItemGroup>
<WriteLinesToFile File="$(projectDir)Scripts\t1\typescriptcompiler.input" Lines="@(T1TypeScriptFiles)" Overwrite="true" Encoding="UTF-8" />
<Exec Command=""$(MSBuildProgramFiles32)\Microsoft SDKs\TypeScript\$(TypeScriptToolsVersion)\tsc" --out $(projectDir)Scripts\t1\t1.js --target ES5 @$(projectDir)Scripts\t1\typescriptcompiler.input" CustomErrorRegularExpression="\.ts\([0-9]+,[0-9]+\):(.*)">
</Exec>
</Target>

Found conflicts between different versions of the same dependent assembly. Please set the “AutoGenerateBindingRedirects” property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190.

Considering there are about 50 references across the projects I have in this solution, that isn’t particularly helpful.

There is an easy way to get the compiler to spit out more information.

  1. In Visual Studio 2013 go to Tools > Options.
  2. Select Project and Solutions > Build and Run.
  3. Find the drop down MSBuild project build output verbosity. Here you can configure MSBuild to give you more information. By default it will be set to “Minimal”. Change this to “Detailed’.
  4. Rebuild and view the Output window. Copy everything into notepad and search for the warning which should tell you which assemblies you need to look at.

Now a days I can see that just before the ending of the tag something like below appears:

1
<div id="GOOGLE_INPUT_CHEXT_FLAG" style="display: none;" input="" input_stat="{}"></div>

I can see this in every webpages whenever I try to Inspect Element in Google Chrome.

I have got the point. Its because of the extension: Google Input Tools (by Google).

Enabling Execution of PowerShell PS1 Scripts

1
Set-ExecutionPolicy Unrestricted

You can see exactly what versions Powershell is using by examining the value of $PSVersionTable

PSVersionTable2

Notice the value or CLRVersion begins with a “2”.

Being lazy, of course, we hate manual steps, so here is a small PowerShell script that will automatically create and place the necessary files. Be aware that the script as shown below will overwrite existing .config files.

1
2
3
4
5
6
7
8
9
10
11
12
$config_text = @"
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
"@

$config_text| Out-File $pshome\powershell.exe.config
$config_text| Out-File $pshome\powershell_ise.exe.config

Start PowerShell as an Administrator an then run the script.

Now restart PowerShell and examine the value of $PSVersionTable.

PSVersionTable4

And now your .NET 4.0 module will load correctly.