Tag Archives: mvc

DateTime not parsing MM/dd/yyyy correctly on Windows 10 on ASP .Net MVC

Have you experienced coding and all of a sudden when on windows 10 you experienced that MM/dd/yyyy is not a valid date? This is because of the culture that is default implemented on your device, in this case on my device with Windows 10 Pro. To cause of this is the machine is by default is using dd/MM/yyyy and in this case apps that we are developing is having this kind of issue.

Thank fully the fastest way to fix is via the web.config with the following code:

<system.web>

<globalization culture=”en-US” uiCulture=”en-US”/>

 

And then run again your application and it will now accept your MM/dd/yyyy.

ELMAH – Error Logging Modules and Handlers

What is ELMAH?

  • ELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
  • Once ELMAH has been dropped into a running web application and configured appropriately, you get the following facilities without changing a single line of your code:
    • Logging of nearly all unhandled exceptions.
    • A web page to remotely view the entire log of recoded exceptions.
    • A web page to remotely view the full details of any one logged exception, including colored stack traces.
    • In many cases, you can review the original yellow screen of death that ASP.NET generated for a given exception, even with customErrors mode turned off.
    • An e-mail notification of each error at the time it occurs.
    • An RSS feed of the last 15 errors from the log.

How to Install ELMAH on your MVC Project?

  • Open Nuget Package Manager on the MVC Project
  • Search for ELMAH and Install it.
  • Then configure it.

ELMAH Configuration

  • It will already add some configuration under your web.config but we need to include some configuration so that it will point to a database.
  • <connectionStrings>

  <add name=”elmahConnectionString” connectionString=”Data Source=Server;Initial Catalog=ELMAH_DEV;uid=user;pwd=user;Pooling=true;Min Pool Size=0;Max Pool Size=999;” providerName=”System.Data.SqlClient” />

</connectionStrings>

  • <elmah>

    <!–

See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for

more information on remote access and securing ELMAH.

–>

<security allowRemoteAccess=”true” />

<errorLog type=”Elmah.SqlErrorLog, Elmah” applicationName=”NameOfApplication_DEV” connectionStringName=”elmahConnectionString” />

</elmah>

  • We also need to remove some sections that we don’t need specially the section below that automatically create a page for the logs.
  • <location path=”elmah.axd” inheritInChildApplications=”false”>…</location>

Logging

  • All uncatched exception will automatically be recorded.
  • All exception handling will NOT be recorded automatically. It needs to be manually logged by including the Elmah.ErrorSignal.FromCurrentContext().Raise(ex);

try{
throw new Exception(“Some Exception”);
}catch(Exception ex){

Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
}

 

Opencast, Your Free and Open Video Casting!

Hi There,

We are glad to invite you to our first Free service product, OpenCast. OpenCast is an online broadcasting websites that aim to help people broadcast freely and openly. The website is created using ASP.Net MVC, Entity Framework, SignalR, & OpenTok.

 

Feel Free to register now at http://opencast.info

God Bless!

Thanks,
Thomie

A potentially dangerous Request.Form value was detected from the client

Have you ever experience the following error in ASP .NET?

A potentially dangerous Request.Form value was detected from the client 

Then you are one like me. Then you should now that one of the values of your elements (<inputs> or <button> or <textarea>) has html elements on it. Example is bellow:

<input type=’text’ name=’content’ value='<script language=”javascript”>alert(“Hello World!”);</script>’/>

Then you should also know that this error is persisting because the values given above might be an XSS attack. If you are sure that you want to accept this type of values on your dabatase you may explicitly remove this validation by adding this tag to your page’s masterpage or 1st line of tag.

validateRequest=”false”

If you are on ASP .NET MVC you can add this to your model, assuming that your model has the content variable.

[AllowHtml]
public string content = String.Empty;

Thanks hope it help you allot. Also if you are not familiar with XSS attacks, I will try to make an article for that so you can create your own script that is hack-able, be able to prevent it, and know what are it’s crons.

God Bless!

jQuery Extension for ASP .Net MVC

My boss told us to search for a jQuery Extension for ASP .Net MVC to make the development easier. After minutes of searching the web I have found two extensions that you and I can use:

  1. DJME 2 which is an free and Open source
  2. Telerik Extensions for ASP .NET in this case is a paid extension

Both extensions utilizes the creation of custom helper to make jQuery development quite easier but abstracted. Abstracted because you are learning how the extensions should be use to produce jQuery but your not really coding jQuery. 

So in the end, I will still recommend using jQuery it self, doing all the hard works of creating the JavaScript file and code all the way, so you can produce the right jQuery output you have ever wanted.

ASP .Net MVC 3 – WebMail

Hi,

I have been searching the web on how to easily send email thru ASP .NET MVC 3 and finally found the right code for it, its called WebMail. Look at the code below and insert it to one of your Controller’s Action:

WebMail.SmtpServer = “smtp.gmail.com”;
WebMail.EnableSsl = true;
WebMail.SmtpPort = 25;
WebMail.UserName = “[email protected]”;
WebMail.Password = “**********”;
WebMail.From = “[email protected]”;
WebMail.Send(“********@******.com”, subject:”Subject”, body:”Message Here”);

Then try it on!

Its the Easiest Email on ASP .Net mvc 3 using webmail using gmail!